I made myself crazy with this throughout the day, searched high and low, and probably trying to be too sweet, so I was completely stuck.
I try to run simple if then
If the cell contains "%", I would like it to do one thing, and if not another. For reasons that I do not understand, I cannot get it to work. I clearly took a couple of ideas from other sources, but still can't get it to work.
Complicating factors. I donβt want to run this on the whole column, just a table, so it is built into most using batches or relative ActiveCells. I never know where in column A I'm going to run β% Change,β so Range should always be variable. I want VBA / VBE to do something different when it comes to a cell with "%" in it. SO
Here's what the raw data looks like.
Initial Value (6/30/06) Value (12/31/06) Net Additions (9/30/07) Withdrawal (12/07) Value (12/31/07) Withdrawal (2008) Value (12/31/08) Addition (8/26/09) Value (12/31/09) Value (12/31/10) Value (12/30/11) Value (3/31/12) % Change 1st Quarter % Change Since Inception
But when I run the following, it gets stuck in a bad loop, where it should have pulled into the "If Then" as opposed to the "Else" part of the sub.
Sub IfTest() 'This should split the information in a table up into cells Dim Splitter() As String Dim LenValue As Integer 'Gives the number of characters in date string Dim LeftValue As Integer 'One less than the LenValue to drop the ")" Dim rng As Range, cell As Range Set rng = ActiveCell Do While ActiveCell.Value <> Empty If InStr(rng, "%") = True Then ActiveCell.Offset(0, 0).Select Splitter = Split(ActiveCell.Value, "% Change") ActiveCell.Offset(0, 10).Select ActiveCell.Value = Splitter(1) ActiveCell.Offset(0, -1).Select ActiveCell.Value = "% Change" ActiveCell.Offset(1, -9).Select Else ActiveCell.Offset(0, 0).Select Splitter = Split(ActiveCell.Value, "(") ActiveCell.Offset(0, 9).Select ActiveCell.Value = Splitter(0) ActiveCell.Offset(0, 1).Select LenValue = Len(Splitter(1)) LeftValue = LenValue - 1 ActiveCell.Value = Left(Splitter(1), LeftValue) ActiveCell.Offset(1, -10).Select End If Loop End Sub
All help is appreciated, thanks!