Monty_Python
New Member
- Joined
- Feb 9, 2021
- Messages
- 2
- Office Version
- 2010
- Platform
- Windows
Hi All,
I'm trying to speed up a bit process of data validation, but I got stuck with too many ideas and no clear solution to my VBA code.
I've just started my macro/VBA fun, so getting a piece of information is great, but combing this into 1 logical way, for now, doesn't work for me.
What I have:
Excel file where starting from column R row 13 I have loads of cells. Depending on the file sometimes those data are only in column R, sometimes I have more columns this is why I need to include the Last Column. When it comes to the number of rows - they also differ, so I assume relative could help here.
Every column has blanks, which can't be deleted, but definitely, for a further purpose, the formula TRIM has to skip those blanks.
And the last point - when I have my range defined & blanks cells are instructed to be omitted I need to trim the data including both sides (before and after the wording, not between).
The last version of my formula which has an error looks like that :
Sub Trim_Data()
Dim DataRange As Range
Set DataRange = Range("R13:W" & LastRow)
Set R = Selection
If rng <> "" Then
For Each cell In rng
cell.Value = WorksheetFunction.Trim(cell)
Next
End If
End Sub
I'd much appreciate if anyone could help me with correcting ( or totally changing) the script.
Thank you!
I'm trying to speed up a bit process of data validation, but I got stuck with too many ideas and no clear solution to my VBA code.
I've just started my macro/VBA fun, so getting a piece of information is great, but combing this into 1 logical way, for now, doesn't work for me.
What I have:
Excel file where starting from column R row 13 I have loads of cells. Depending on the file sometimes those data are only in column R, sometimes I have more columns this is why I need to include the Last Column. When it comes to the number of rows - they also differ, so I assume relative could help here.
Every column has blanks, which can't be deleted, but definitely, for a further purpose, the formula TRIM has to skip those blanks.
And the last point - when I have my range defined & blanks cells are instructed to be omitted I need to trim the data including both sides (before and after the wording, not between).
The last version of my formula which has an error looks like that :
Sub Trim_Data()
Dim DataRange As Range
Set DataRange = Range("R13:W" & LastRow)
Set R = Selection
If rng <> "" Then
For Each cell In rng
cell.Value = WorksheetFunction.Trim(cell)
Next
End If
End Sub
I'd much appreciate if anyone could help me with correcting ( or totally changing) the script.
Thank you!