Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I'm having problems trying to do a loop for a spreadsheet in VB for Excel. I have a spreadsheet with records that include the fields: district number, school number, and school name. The number of records will vary for each spreadsheet depending on how many schools I have. I'd like to copy and paste columns A:C to another worksheet after each change in district number with as little code as possible as I approximately 1200 schools. Any help would be appreciated.

write all your records on a single sheet, delete sheet 2 and 3; after create a macro with this code:
Sub separation()
Dim CellaAttuale, CellaPrec As Integer
'Valore = Worksheets("Foglio1").Cells(1, 1).Value
CellaPrec = Worksheets("Foglio1").Cells(1, 1).Value
y = 0
For j = 2 To 6
CellaAttuale = Worksheets("Foglio1").Cells(j, 1).Value
If CellaAttuale CellaPrec Then
MsgBox (CellaAttuale & " (cella attuale) diversa dalla prec: " & CellaPrec)
Worksheets.Add.Move after:=Worksheets(Worksheets.Count)
Worksheets(Worksheets.Count).Name = CellaAttuale
Worksheets(Worksheets.Count).Cells(j, 1).Value = Worksheets("Foglio1").Cells(j, 1).Value
y = 0
Else
If Worksheets.Count > 1 Then
y = y + 1
Worksheets(Worksheets.Count).Cells(y, 1).Value = Worksheets("Foglio1").Cells(j, 1).Value
End If
End If
CellaPrec = CellaAttuale
Next j
End SubIt doesn't work properly, it's just an idea to improve...
I hope an useful examble, try it and improve the code, otherwise to pass to a DB is the best thing to do (like tech-fred said)...

![]() |
Ada Help again
|
what is a scripting langu...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |