Forum Discussion

matthewwwood's avatar
matthewwwood
Copper Contributor
Dec 14, 2023
Solved

Excel macro help - cutting off first letter of some results in pivot

I need help with a macro problem I can't figure out. Some of the cells return a field that's missing the first letter of the data. What's wrong with the code where it does this? For instance, in the ...
  • djclements's avatar
    djclements
    Dec 15, 2023

    matthewwwood The most likely culprit is the use of the Mid function to exclude the leading character(s) from columns 2 and 3:

     

        ' Split phrases in column 2 and copy corresponding data
        For i = 2 To LastRow
            phrases1 = Split(Mid(rootData.Cells(i, 2).value, 2), ",")
        
        ...
        
        ' Split phrases in column 3 and copy corresponding data
        For i = 2 To LastRow
            phrases2 = Split(Mid(rootData.Cells(i, 3).value, 3), ",")

     

    For column 2, the Start position is 2, but for column 3 the Start position is 3. Is this a typo? Should it be 2 for both? If not, then...

     

    Do all of the cells in columns 2 and 3 contain the same number of leading character(s) that you are trying to exclude? I would start by examining the source data... locate the cell that contains "microgrids" and verify that it follows the same pattern as the other cells regarding leading characters.

Resources