need another set of eyes to look at this

RAYLWARD102

Well-known Member
Joined
May 27, 2010
Messages
529
I have an if statement that is used to switch the column that the data is being posted in. I want it to switch every line from g to i columns
each time it does a line.
I'm not sure; but for some reason, it does the first line to G and all of the rest after to I. I never gets set back to g. Any idea's why?


Code:
Sub SCpgCREATE()

Set config = Worksheets("config") 'parameter sheet
Set ImPP = Worksheets("IMPORTED") 'import sheet
Set scPG = Worksheets("SCANpage") 'special sheet print offs

Dim iUPcol As String
    iUPcol = config.Range("c16").Value
Dim iITEcol As String
    iITEcol = config.Range("c17").Value
Dim iNMcol As String
    iNMcol = config.Range("c18").Value
Dim iPKGcol As String
    iPKGcol = config.Range("c19").Value
Dim iCScol As String
    iCScol = config.Range("c20").Value
Dim iMakcol As String
    iMakcol = config.Range("c21").Value
Dim cntr As Long
    cntr = 1
Dim SCupCOL As String
    SCupCOL = "G"

iRow2 = ImPP.Cells(Rows.Count, config.Range("c16").Value).End(xlUp).Row 'bottom col in import sheet
    
    For Each cell In ImPP.Range(iUPcol & "1:" & iUPcol & iRow2).Cells
        scPG.Range("a" & cntr).Value = ImPP.Range(iMakcol & cell.Row).Value
        scPG.Range("b" & cntr).Value = ImPP.Range(iNMcol & cell.Row).Value
        scPG.Range("c" & cntr).Value = ImPP.Range(iPKGcol & cell.Row).Value
        scPG.Range("d" & cntr).Value = ImPP.Range(iCScol & cell.Row).Value
        scPG.Range([COLOR=Red]SCupCOL[/COLOR] & cntr).Value = ImPP.Range(iUPcol & cell.Row).Value
[COLOR=Red]        If SCupCOL = "G" Then
            SCupCOL = "I"
            Else:
            sUPcol = "G"
        End If[/COLOR]
        
        cntr = cntr + 1
    Next cell

End Sub
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
ya...in the if statement I'm saying if supcol = g .....change it to I .
Then When it gets back to the if statement on the next line; vice versa....should switch the two around every line.
 
Upvote 0
figured it out......I spelled the variable wrong!
supcol should have been scupcol
thanks for looking

I'd reccommend using Option Explicit in your code to avoid things like this. ;)

By putting Option Explicit at the top of your module (before any procedures), it forces you to explicitly declare every single variable you use. If you happen to misspell something, it will find that misspelling, and point it out to you when you try to run the code.
 
Upvote 0

Forum statistics

Threads
1,224,597
Messages
6,179,808
Members
452,944
Latest member
2558216095

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top