Hello all! I am trying to figure out a way to read a cell in worksheet A, search for the string in worksheet B and then copy that whole row to worksheet C. I am missing something and I keep tweaking the code and feel like I am making it worse and worse so I am going to post what I have and hopefully someone can help!
Private Sub CommandButton1_Click()
Dim c As Range
Dim d As Range
Dim Source As Worksheet
Dim Target As Worksheet
Dim Data As Worksheet
Dim LSearchRadio As Integer
Dim LCopyToRadio As Integer
Dim LRadioString As String
Dim LRadioCounter As Integer
' Change worksheet designations as needed
Set Data = Me.Parent.Worksheets("SysData")
Set Source = Me.Parent.Worksheets("Report")
Set Target = Me.Parent.Worksheets("Radio")
'Start search in row 2
LSearchRadio = 2
'Start copying data to row 1 in Radio (row counter variable)
LCopyToRadio = 2
'Start the Radio Counter
LRadioCounter = 2
For Each c In Data.Range("A1:A3") ' Do 1000 rows in SysData for Radio
With c.Value = True
'Copy the next TAM
LRadioString = Range(Data.["A"] & CStr(LRadioCounter)).Value
Do While Range(Data.["A"] & CStr(LRadioCounter)).Value <> "" ' Do rows in Report
Source.Select
'If value in Report Worksheet on column M = String From SysData, copy entire row to Radio
If Range(Source.["M"] & CStr(LSearchRadio)).Value = LRadioString Then
'Select row in Report to copy
Source.Select
Source.Rows(CStr(LSearchRadio) & ":" & CStr(LSearchRadio)).Select
Selection.Copy
'Paste row into Radio in next row
Target.Select
Target.Rows(CStr(LCopyToRadio) & ":" & CStr(LCopyToRadio)).Select
Target.Paste
'Move counter to next row
LCopyToRadio = LCopyToRadio + 1
'Go back to Report to continue searching
'End if for Copy
End If
LSearchRadio = LSearchRadio + 1
Loop
'Goto next TAM on SysData for Radio
LRadioCounter = LRadioCounter + 1
End With
Next c
End Sub
Private Sub CommandButton1_Click()
Dim c As Range
Dim d As Range
Dim Source As Worksheet
Dim Target As Worksheet
Dim Data As Worksheet
Dim LSearchRadio As Integer
Dim LCopyToRadio As Integer
Dim LRadioString As String
Dim LRadioCounter As Integer
' Change worksheet designations as needed
Set Data = Me.Parent.Worksheets("SysData")
Set Source = Me.Parent.Worksheets("Report")
Set Target = Me.Parent.Worksheets("Radio")
'Start search in row 2
LSearchRadio = 2
'Start copying data to row 1 in Radio (row counter variable)
LCopyToRadio = 2
'Start the Radio Counter
LRadioCounter = 2
For Each c In Data.Range("A1:A3") ' Do 1000 rows in SysData for Radio
With c.Value = True
'Copy the next TAM
LRadioString = Range(Data.["A"] & CStr(LRadioCounter)).Value
Do While Range(Data.["A"] & CStr(LRadioCounter)).Value <> "" ' Do rows in Report
Source.Select
'If value in Report Worksheet on column M = String From SysData, copy entire row to Radio
If Range(Source.["M"] & CStr(LSearchRadio)).Value = LRadioString Then
'Select row in Report to copy
Source.Select
Source.Rows(CStr(LSearchRadio) & ":" & CStr(LSearchRadio)).Select
Selection.Copy
'Paste row into Radio in next row
Target.Select
Target.Rows(CStr(LCopyToRadio) & ":" & CStr(LCopyToRadio)).Select
Target.Paste
'Move counter to next row
LCopyToRadio = LCopyToRadio + 1
'Go back to Report to continue searching
'End if for Copy
End If
LSearchRadio = LSearchRadio + 1
Loop
'Goto next TAM on SysData for Radio
LRadioCounter = LRadioCounter + 1
End With
Next c
End Sub