variable help

rickblunt

Well-known Member
Joined
Feb 18, 2008
Messages
609
Office Version
  1. 2019
Platform
  1. Windows
Hello, I am using the code below to transfer some data between worksheets, and it works fine. I had the code set to a specific value but I was having to tweak the code every now and then so that the user could change the trigger point. I figured it would be easier on both of us if I just added a cell to the worksheet so that the user could change the setpoint on the fly. So I added a new WS called "Coding" and assigned cell C2 for that. I get no error messages but the code does not transfer the data as it did before. Can anyone tell me what I did wrong, I am missing something simple I know - Thank you,


VBA Code:
Sub CopyEpipro()
    Dim c As Range
    Dim j As Integer
    Dim Source As Worksheet
    Dim Target As Worksheet
    Dim setpoint As Integer 'I added this
    
    Set Source = ActiveWorkbook.Worksheets("EPIPRO")
                     
    Set Target = ActiveWorkbook.Worksheets("Export")
                   
    setpoint = ActiveWorkbook.Worksheets("Coding").Range("C2") ' I added this
    
    j = 45     ' Start copying to row 1 in target sheet
    For Each c In Source.Range("H5:H12")   ' The column for the micron reading
        If c >= setpoint Then  'this was  "if>= 2900 then" before I tried to add the setpoint variable
           Source.Rows(c.Row).Copy Target.Rows(j)
           j = j + 1
        End If
    Next c
End Sub
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
The code is working, I think the j = 45 might be what is not correct for you.

The code does transfer, in it's current state, to the 'Export' sheet starting at row 45 when condition is met ie >= 2900
 
Upvote 0
Hi johnnyL, thanks for looking at this. And yup, I reopened the WB and it is working just fine just like you said. Puzzled to why it wasn't working before, oh well - lol. I appreciate your input and you double checking my syntax :)
 
Upvote 0
Your comment line for j = 45 says to start at row 1 so that was the only issue I could see. Glad it is working now as you expected.
 
Upvote 0

Forum statistics

Threads
1,214,387
Messages
6,119,222
Members
448,877
Latest member
gb24

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