I have a large VBA script file that references the cells of an excel worksheet. The problem is that the number of the application properties I have placed horizontally is becoming larger than 256, therefore I have to change the orientation of storing the properties.
So instead of accessing a value with .Cells(row, column).Value, I would like to access everything by swapping the rows and columns in the previous call.
I could go from all the code and manually change everything, but I would prefer to use a regular expression. I came up with this to find all the references I need:
Worksheets\(\"xxx\.DAT\"\)\.Cells\([\w +-]{1,15}, [\w +-]{1,15}\)
Results look something like this Worksheets(“xxx.DAT”).Cells(SystemNr + 1, 21 + Row1)
I want to swap the rows with the columns in the call to the Cells property, so the end result should look like Worksheets(“xxx.DAT”).Cells(21 + Row1, SystemNr + 1)
I made a small .NET application and used the code bellow to get all the matches, but how do I swap the rows with the columns in the matches themselves?
string input = tbContent.Text;
foreach (Match match in Regex.Matches(input, tbRegex.Text, RegexOptions.IgnorePatternWhitespace))
{
tbResult.AppendText(match + Environment.NewLine);
}
Now, for every match I’d like to get a reference of the row index and one of the column index so I can swap them and replace the original text.
Thanks,
Adrian.
I am not sure how you source data looks like, but here is a short c# example on how to swap two things:
If you create a capturing group, by putting a subpattern into brackets, you can access the matches of those subpatterns in the replacement string. The first group (defined by the first opening round bracket) is accessed by
$1, the second by$2. So in this basic example just replace with the second group and as second with the first group, that way you changed the order of your submatches.