castklefamilies
New Member
- Joined
- Sep 12, 2019
- Messages
- 3
Hello,
Any help would be appreciated as I am still new and learning VBA. I was able to put this code together to allow me to mark an x on one sheet and it copy Columns A, B, D, F to another sheet. I actually need them to copy in the order A,B,F,D instead. I thought it would be as simply as changing the order in the range of the code but that is not working. Here is the code:
Sub Transfer()
Dim wshS As Worksheet
Dim wshT As Worksheet
Dim rng As Range
Dim strAddress As String
Dim s As Long
Dim t As Long
Application.ScreenUpdating = False
Set wshT = Worksheets("Inspection")
t = wshT.Range("B" & wshT.Rows.Count).End(xlUp).Row
If t < 4 Then t = 4
For Each wshS In Worksheets
If wshS.Name <> wshT.Name Then
Set rng = wshS.Range("J:J").Find(What:="X", LookAt:=xlWhole)
If Not rng Is Nothing Then
strAddress = rng.Address
Do
t = t + 1
s = rng.Row
wshS.Range("A" & s & ",B" & s & ",D" & s & ",F" & s).Copy _
Destination:=wshT.Range("B" & t)
' Optional: clear the "X"
wshS.Range("J" & s).ClearContents
Set rng = wshS.Range("J:J").FindNext(After:=rng)
If rng Is Nothing Then Exit Do
Loop Until rng.Address = strAddress
End If
End If
Next wshS
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub
Any help would be greatly appreciated.
Dustin
Any help would be appreciated as I am still new and learning VBA. I was able to put this code together to allow me to mark an x on one sheet and it copy Columns A, B, D, F to another sheet. I actually need them to copy in the order A,B,F,D instead. I thought it would be as simply as changing the order in the range of the code but that is not working. Here is the code:
Sub Transfer()
Dim wshS As Worksheet
Dim wshT As Worksheet
Dim rng As Range
Dim strAddress As String
Dim s As Long
Dim t As Long
Application.ScreenUpdating = False
Set wshT = Worksheets("Inspection")
t = wshT.Range("B" & wshT.Rows.Count).End(xlUp).Row
If t < 4 Then t = 4
For Each wshS In Worksheets
If wshS.Name <> wshT.Name Then
Set rng = wshS.Range("J:J").Find(What:="X", LookAt:=xlWhole)
If Not rng Is Nothing Then
strAddress = rng.Address
Do
t = t + 1
s = rng.Row
wshS.Range("A" & s & ",B" & s & ",D" & s & ",F" & s).Copy _
Destination:=wshT.Range("B" & t)
' Optional: clear the "X"
wshS.Range("J" & s).ClearContents
Set rng = wshS.Range("J:J").FindNext(After:=rng)
If rng Is Nothing Then Exit Do
Loop Until rng.Address = strAddress
End If
End If
Next wshS
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub
Any help would be greatly appreciated.
Dustin