ah2024_2024
New Member
- Joined
- Jun 18, 2024
- Messages
- 14
- Office Version
- 365
- Platform
- Windows
Please do not roast me, I have extensive knowledge in formulas and basic knowledge in VBA (but only by trial and error and lots of Google assistance.
I'm attempting to use the code below to copy and paste data from column F of sheet3 (if A1 on the FTW cell match names in column F of sheet3) to A9, A10 and so forth on the FTW sheet. I do not want to replace or copy over any name that is already there. Issue is I'm getting 2 separate errors. I'm getting a compile error and if I can fix that I'm getting an "out of range" error for WITH Sheets("ftw")
Below is what I'm attempting to use:
Sub MOVE_active_reps2()
Dim sourceSheet As Worksheet
Dim targetSheet As Worksheet
Dim lastRow As Long
Dim f As Long, cls
cls = Range("F2:F20000")
Dim v As Variant
' Set the source and target sheets
Set sourceSheet = ThisWorkbook.Worksheets("sheet3")
Set targetSheet = ThisWorkbook.Worksheets("ftw")
' Find the last row in the source sheet
lastRow = sourceSheet.Cells(sourceSheet.Rows.Count, "f").End(xlUp).Row
' Loop through each row in the source sheet
For i = 6 To lastRow
' Check if cell in column f contains "office name"
If sourceSheet.Cells(i, "f").Value = "fort worth" Then
v = sourceSheet.Cells(i, "a").Value
' Check whether value has already been copied
If targetSheet.Range("a:a").Find(What:=v, LookIn:=xlValues, LookAt:=xlWhole) Is Nothing Then
End If
With Sheets("ftw")
LR = WorksheetFunction.Max(9, .Range("A" & Rows.Count).End(xlUp).Row + 1)
For f = LBound(cls) To UBound(cls)
Range(cls(i)).Copy Destination:=.Cells(LR, i + 1)
Next f
End With
End If
End Sub
I'm attempting to use the code below to copy and paste data from column F of sheet3 (if A1 on the FTW cell match names in column F of sheet3) to A9, A10 and so forth on the FTW sheet. I do not want to replace or copy over any name that is already there. Issue is I'm getting 2 separate errors. I'm getting a compile error and if I can fix that I'm getting an "out of range" error for WITH Sheets("ftw")
Below is what I'm attempting to use:
Sub MOVE_active_reps2()
Dim sourceSheet As Worksheet
Dim targetSheet As Worksheet
Dim lastRow As Long
Dim f As Long, cls
cls = Range("F2:F20000")
Dim v As Variant
' Set the source and target sheets
Set sourceSheet = ThisWorkbook.Worksheets("sheet3")
Set targetSheet = ThisWorkbook.Worksheets("ftw")
' Find the last row in the source sheet
lastRow = sourceSheet.Cells(sourceSheet.Rows.Count, "f").End(xlUp).Row
' Loop through each row in the source sheet
For i = 6 To lastRow
' Check if cell in column f contains "office name"
If sourceSheet.Cells(i, "f").Value = "fort worth" Then
v = sourceSheet.Cells(i, "a").Value
' Check whether value has already been copied
If targetSheet.Range("a:a").Find(What:=v, LookIn:=xlValues, LookAt:=xlWhole) Is Nothing Then
End If
With Sheets("ftw")
LR = WorksheetFunction.Max(9, .Range("A" & Rows.Count).End(xlUp).Row + 1)
For f = LBound(cls) To UBound(cls)
Range(cls(i)).Copy Destination:=.Cells(LR, i + 1)
Next f
End With
End If
End Sub