M
Mekinnik
I am trying to grap the data from my search cell by cell and tell it where to
be copied to on a new worksheet. I have managed to get the data copied to the
new sheet but it is not where I want it to be. Here is the code I have
already gotten from here and modified it to try and accomplish what it is
that I want. I do believe one of my problems is that the columns between the
datasheet and the new sheet do not match. The data sheet has only 13 columns
of data and the new sheet has 18 columns, part is due to 2 of the columns are
going to get there data from another data sheet, but that is another problem
for another day. Thank you all for any help with this dilema.
Private Sub BtnGo_Click()
Dim tRow()
Dim WSNew As Worksheet
'Dim rng As Range
Dim T As String
Dim TS As String
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
'creates a new sheet from the master sheet
T = Me.CbxDept.Text
Sheets("MASTER").Copy before:=Sheets(2)
Set WSNew = ActiveSheet
'creates the name of 'WSNew'
WSNew.Name = T
'assigns cell 'J2' equal to 'T'
WSNew.Cells(2, 10) = T
'copies all data that matches 'T' to new sheet
c = 1
Sheets("ProCode").Select
Range("M2").EntireColumn.Select
Selection.Find(What:=T, after:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=True).Activate
ReDim Preserve tRow(c)
tRow(c) = ActiveCell.Row
Do
c = c + 1
Selection.FindNext(after:=ActiveCell).Activate
ReDim Preserve tRow(c)
tRow(c) = ActiveCell.Row
Loop Until tRow(1) = tRow(c)
'Copy cells in column A:M to WSNew
Set tCell = WSNew.Range("A5") ' First destination cell
For R = 1 To c - 1
For Col = 1 To 13
Cells(tRow(c), Col).Copy Destination:=tCell
Set tCell = tCell.Offset(0, 1)
Next
Set tCell = tCell.Offset(1, -(Col - 1)) ' Next row
Next
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub
be copied to on a new worksheet. I have managed to get the data copied to the
new sheet but it is not where I want it to be. Here is the code I have
already gotten from here and modified it to try and accomplish what it is
that I want. I do believe one of my problems is that the columns between the
datasheet and the new sheet do not match. The data sheet has only 13 columns
of data and the new sheet has 18 columns, part is due to 2 of the columns are
going to get there data from another data sheet, but that is another problem
for another day. Thank you all for any help with this dilema.
Private Sub BtnGo_Click()
Dim tRow()
Dim WSNew As Worksheet
'Dim rng As Range
Dim T As String
Dim TS As String
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
'creates a new sheet from the master sheet
T = Me.CbxDept.Text
Sheets("MASTER").Copy before:=Sheets(2)
Set WSNew = ActiveSheet
'creates the name of 'WSNew'
WSNew.Name = T
'assigns cell 'J2' equal to 'T'
WSNew.Cells(2, 10) = T
'copies all data that matches 'T' to new sheet
c = 1
Sheets("ProCode").Select
Range("M2").EntireColumn.Select
Selection.Find(What:=T, after:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=True).Activate
ReDim Preserve tRow(c)
tRow(c) = ActiveCell.Row
Do
c = c + 1
Selection.FindNext(after:=ActiveCell).Activate
ReDim Preserve tRow(c)
tRow(c) = ActiveCell.Row
Loop Until tRow(1) = tRow(c)
'Copy cells in column A:M to WSNew
Set tCell = WSNew.Range("A5") ' First destination cell
For R = 1 To c - 1
For Col = 1 To 13
Cells(tRow(c), Col).Copy Destination:=tCell
Set tCell = tCell.Offset(0, 1)
Next
Set tCell = tCell.Offset(1, -(Col - 1)) ' Next row
Next
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub