swartzfeger
New Member
- Joined
- May 23, 2022
- Messages
- 17
- Platform
- Windows
- MacOS
Hi all, I have (very) limited programming skills and need a simple way to export data based on column name (the column will always be named "Missing #"). I found some VBA that would do the trick with one caveat -- there will always be a different number of columns in this worksheet, so the range of A1:?? will always be different. In the example below, the range is A1:P1... I need a way to determine the actual range for a given sheet. Would something like Range.End or Range.Find be useful?
Also, in the procedure below it simply selects the columns named "Missing #"... is there a way to export the data from the Missing # columns without writing another procedure?
Thanks!
Also, in the procedure below it simply selects the columns named "Missing #"... is there a way to export the data from the Missing # columns without writing another procedure?
Thanks!
VBA Code:
Sub FindMissing()
'11/14/2022
Dim xRg As Range
Dim xRgUni As Range
Dim xFirstAddress As String
Dim xStr As String
On Error Resume Next
xStr = "Missing #"
Set xRg = Range("A1:P1").Find(xStr, , xlValues, xlWhole, , , True)
If Not xRg Is Nothing Then
xFirstAddress = xRg.Address
Do
Set xRg = Range("A1:P1").FindNext(xRg)
If xRgUni Is Nothing Then
Set xRgUni = xRg
Else
Set xRgUni = Application.Union(xRgUni, xRg)
End If
Loop While (Not xRg Is Nothing) And (xRg.Address <> xFirstAddress)
End If
xRgUni.EntireColumn.Select
End Sub