Populate another worksheet

Petartist

New Member
Joined
Aug 26, 2002
Messages
3
Very new to VB (3 days)..I have a workbook that contains 3 worksheets. I have code for populating information from the first sheet into the second. Now I am trying to do the same thing with the 3rd sheet. The problem I am having is that in the first sheet I am taking the values of Col A, B, C and F and populating into Col A, B, C and D only if Col F in the first sheet has an entry and at the same time does not give me blank rows on the sheet I am populating. Here is the code:
Private Sub CommandButton1_Click()
Dim PopEnvCharges()
If ActiveSheet.Name = "EnvelopeCharges" Then
ActiveWorkbook.ActiveSheet.Range("a2:d65536").ClearContents
Dim EnvQuant As Object
Dim EnvChgCell As Object
Set EnvQuant = ActiveWorkbook.Sheets("Chargebacks").Range("F2")
Set EnvChgCell = ActiveWorkbook.Sheets("EnvelopeCharges").Range("A2")
Do Until IsEmpty(EnvQuant.Offset(0, -5))
If EnvQuant.Value <> "" And EnvQuant.Value <> 0 Then
Do Until IsEmpty(EnvChgCell)
Set EnvChgCell = EnvChgCell.Offset(1, 0)
Loop
EnvChgCell.Value = EnvQuant.Offset(0, -5)
EnvChgCell.Offset(0, 1).Value = EnvQuant.Offset(0, -4).Value
EnvChgCell.Offset(0, 2).Value = EnvQuant.Offset(0, -3).Value
EnvChgCell.Offset(0, 3).Value = EnvQuant.Value
End If
Set EnvQuant = EnvQuant.Offset(1, 0)
Loop
End If
End Sub
I want to do the same thing, but now I am populating from Sheet 1 Col A and B into Col A and B of Sheet 3 only if Col N on Sheet 1 has an x in the cell. Can someone help me with the code? This offset thing really has be stumped. Can anyone explain it?
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

brettvba

MrExcel MVP
Joined
Feb 18, 2002
Messages
1,030
On 2002-08-28 20:06, Petartist wrote:
Very new to VB (3 days)..I have a workbook that contains 3 worksheets. I have code for populating information from the first sheet into the second. Now I am trying to do the same thing with the 3rd sheet. The problem I am having is that in the first sheet I am taking the values of Col A, B, C and F and populating into Col A, B, C and D only if Col F in the first sheet has an entry and at the same time does not give me blank rows on the sheet I am populating. Here is the code:
Private Sub CommandButton1_Click()
Dim PopEnvCharges()
If ActiveSheet.Name = "EnvelopeCharges" Then
ActiveWorkbook.ActiveSheet.Range("a2:d65536").ClearContents
Dim EnvQuant As Object
Dim EnvChgCell As Object
Set EnvQuant = ActiveWorkbook.Sheets("Chargebacks").Range("F2")
Set EnvChgCell = ActiveWorkbook.Sheets("EnvelopeCharges").Range("A2")
Do Until IsEmpty(EnvQuant.Offset(0, -5))
If EnvQuant.Value <> "" And EnvQuant.Value <> 0 Then
Do Until IsEmpty(EnvChgCell)
Set EnvChgCell = EnvChgCell.Offset(1, 0)
Loop
EnvChgCell.Value = EnvQuant.Offset(0, -5)
EnvChgCell.Offset(0, 1).Value = EnvQuant.Offset(0, -4).Value
EnvChgCell.Offset(0, 2).Value = EnvQuant.Offset(0, -3).Value
EnvChgCell.Offset(0, 3).Value = EnvQuant.Value
End If
Set EnvQuant = EnvQuant.Offset(1, 0)
Loop
End If
End Sub
I want to do the same thing, but now I am populating from Sheet 1 Col A and B into Col A and B of Sheet 3 only if Col N on Sheet 1 has an x in the cell. Can someone help me with the code? This offset thing really has be stumped. Can anyone explain it?

Hi

Offset is when you move the number of cells,rows specified for example

range("a1").offset(1,0) = a2
and range("a2").offset(0,1 = b1

Brett
 

Forum statistics

Threads
1,147,510
Messages
5,741,582
Members
423,669
Latest member
necat02

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
Top