Hello MrExcel community
Hoping to find help here as i am struggling a bit wuth building a macro using VBA
My requirement is to select few particular colums and extract to a particular named sheet and then sort it according to criteria of one particular column
the problem i am currently facing is when i am running a main module with multiple sub modules it doesnt run them all,
Coulmn A - Text
Column B - Numbers
Column F - Text
So initial sheet is -
intermediate result should be extract of only highlighted columns A B F in seperate sheet -
and finally a sort as based on column F -
VBA Code
Sub FindAColumn()
'trial
Dim xRg As Range
Dim xRgUni As Range
Dim xFirstAddress As String
Dim xStr As String
On Error Resume Next
xStr = "A"
Set xRg = Range("A1:P1").Find(xStr, , xlValues, xlPart, , , True)
If Not xRg Is Nothing Then
xFirstAddress = xRg.Address
Do
If xRgUni Is Nothing Then
Set xRgUni = Range(xFirstAddress)
Else
Set xRgUni = Application.Union(xRgUni, xRg)
End If
Set xRg = Range("A1:P1").FindNext(xRg)
Loop While (Not xRg Is Nothing) And (xRg.Address <> xFirstAddress)
End If
xRgUni.EntireColumn.Select
Selection.Copy
Findrightsheet
Set destination = Sheets("Dataformatted")
'find empty Column (actually cell in Row 1)'
emptyColumn = destination.Cells(1, destination.Columns.Count).End(xlToLeft).Column + 1
If destination.Cells(1, 1) = "" And emptyColumn = 2 Then emptyColumn = 1
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub
But this does not work after the 1st column if i have a seperate module with same code replacing with coulmn B and C,
Please help !
thanks!
Hoping to find help here as i am struggling a bit wuth building a macro using VBA
My requirement is to select few particular colums and extract to a particular named sheet and then sort it according to criteria of one particular column
the problem i am currently facing is when i am running a main module with multiple sub modules it doesnt run them all,
Coulmn A - Text
Column B - Numbers
Column F - Text
So initial sheet is -
intermediate result should be extract of only highlighted columns A B F in seperate sheet -
and finally a sort as based on column F -
VBA Code
Sub FindAColumn()
'trial
Dim xRg As Range
Dim xRgUni As Range
Dim xFirstAddress As String
Dim xStr As String
On Error Resume Next
xStr = "A"
Set xRg = Range("A1:P1").Find(xStr, , xlValues, xlPart, , , True)
If Not xRg Is Nothing Then
xFirstAddress = xRg.Address
Do
If xRgUni Is Nothing Then
Set xRgUni = Range(xFirstAddress)
Else
Set xRgUni = Application.Union(xRgUni, xRg)
End If
Set xRg = Range("A1:P1").FindNext(xRg)
Loop While (Not xRg Is Nothing) And (xRg.Address <> xFirstAddress)
End If
xRgUni.EntireColumn.Select
Selection.Copy
Findrightsheet
Set destination = Sheets("Dataformatted")
'find empty Column (actually cell in Row 1)'
emptyColumn = destination.Cells(1, destination.Columns.Count).End(xlToLeft).Column + 1
If destination.Cells(1, 1) = "" And emptyColumn = 2 Then emptyColumn = 1
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub
But this does not work after the 1st column if i have a seperate module with same code replacing with coulmn B and C,
Please help !
thanks!