quick code adjustment please

d0wnt0wn

Well-known Member
Joined
Oct 28, 2002
Messages
771
hi there I am just trying to adjust this code so that when it pastes the new info it starts on the 3rd row. Currently it starts on the 2nd row and erases information I need.... I have pretty much tried adjusting everything but cant do it.

Sub Fargos()

Dim wsScores As Worksheet
Dim wsFargos As Worksheet
Dim LastRow As Long 'last populated row column B, products sheet
Dim i As Long 'loop variable
Dim Counter As Long 'row counter for PO sheet

Set wsScores = Sheets("Scores")
Set wsFargos = Sheets("Fargos")

With wsFargos
Range("A3:C100").Select
Selection.ClearContents
End With

'find last populated row, column A, Scoresheet
With wsScores
LastRow = .Range("A" & .Rows.Count).End(xlUp).Row
End With

Counter = 1 'row counter Main sheet
'loop through products sheet
For i = 1 To LastRow 'assuming header row
'check if column B is empty
If wsScores.Range("A" & i).Value <> "" Then
Counter = Counter + 2
wsFargos.Range("A" & Counter).Value = wsScores.Range("A" & i).Value
wsFargos.Range("B" & Counter).Value = wsScores.Range("B" & i).Value
wsFargos.Range("C" & Counter).Value = wsScores.Range("C" & i).Value
wsFargos.Range("D" & Counter).Value = wsScores.Range("D" & i).Value
End If
Next i

Range("A3:D100").Select
ActiveWorkbook.Worksheets("Fargos").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Fargos").Sort.SortFields.Add Key:=Range("A3:A100") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Fargos").Sort.SortFields.Add Key:=Range("C3:C100") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Fargos").Sort
.SetRange Range("A3:D100")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Try changing this line of code:
Code:
Counter = 1     'row counter Main sheet

To this:
Code:
Counter = 2     'row counter Main sheet
 
Upvote 0
no that does something weird and pastes things way down the page like it does half of them right then pastes the other half all messed up
 
Upvote 0
I assume you did not write the script and neither did I. This is part of the problem when your using code you did write and do not understand. A lot of things going on in this script.
no that does something weird and pastes things way down the page like it does half of them right then pastes the other half all messed up
 
Upvote 0

Forum statistics

Threads
1,215,402
Messages
6,124,708
Members
449,182
Latest member
mrlanc20

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