PDA

View Full Version : new to vba



blntfrctrma
07-30-2009, 09:24 AM
hello to all,

i am new to vba, and when i mean new i mean i had no idea anything like it existed until now. im currently taking the "fast track" learning program to write some basic code and im having problems picking up what im doing wrong. if someone can point out what im doing wrong it would be much appriciated. this is the code that im using at the moment.


Private Sub donkey()
Worksheets("sheet1").Select
Range("e9").Select
If Worksheets("sheet1").Range("f10").Value = "1" Then
Worksheets("sheet1").Range("e9").Value = "Line 1"
Worksheets("sheet1").Range("e9").Font.Size = "16"
Worksheets("sheet1").Range("e9").Font.Bold = True
ElseIf Worksheets("sheet1").Column("f") <> "1" Then
InsertRow.Offset(-1, 0).Select
Range("E").Offset(-1, 0).Select
Worksheets("sheet1").Column("e").Value = "Line 3"
Worksheets("sheet1").Range("e").Font.Size = "16"
Worksheets("sheet1").Range("e").Font.Bold = True
End If

End Sub

what i want this code to do is to categorize the lines(there are 30 total). now being new im not up on the vocabulary i need to properly explain so ill do my best. column "f" is organized in ascending order(the lines numbers are all over the map). column "e" is the type of work that needs to be done. i want to be able to separate where the lines start and end with the appropriate line number using column "F" to decide where to insert the separation. on top of that in the inserted row i want the line number's title to appear. i hope i explained this enough for someone to give me a bit of insight thank you kindly for any assistance.

Bob Phillips
07-30-2009, 09:31 AM
Your best bet would be to post a workbook with a before sheet and an after sheet. It will do far better than a thousand words.

blntfrctrma
07-30-2009, 09:37 AM
due to sensitivity/confidentiality i dont think that id be allowed to do that. that is why i tried to describe it as best as possible.

p45cal
07-30-2009, 09:59 AM
I agree with xld, post a workbook with a before sheet and an after sheet. If the data is sensitive, make the data up. Your request is nigh on impossible to interpret.

blntfrctrma
07-30-2009, 10:34 AM
ok this is the "finished product" if you will

blntfrctrma
07-30-2009, 10:35 AM
this is how it started out

so i want this spreadsheet to have the line numbers inserted at their proper intervals so that you can see where the information to one line ends and another begins.does that make sense now?

Bob Phillips
07-30-2009, 11:03 AM
Public Sub ProcessData()
Dim i As Long
Dim LastRow As Long

With ActiveSheet

LastRow = .Cells(.Rows.Count, "F").End(xlUp).Row
For i = LastRow To 8 Step -1

If .Cells(i, "F").Value <> .Cells(i - 1, "F").Value Then

.Rows(i).Insert
.Cells(i, "E").Value = "Line " & .Cells(i + 1, "F").Value
End If
Next i
End With

End Sub

blntfrctrma
07-30-2009, 11:28 AM
that works great, is there a way to have it modify the font and size as well?

Bob Phillips
07-30-2009, 12:44 PM
Public Sub ProcessData()
Dim i As Long
Dim LastRow As Long

With ActiveSheet

LastRow = .Cells(.Rows.Count, "F").End(xlUp).Row
For i = LastRow To 8 Step -1

If .Cells(i, "F").Value <> .Cells(i - 1, "F").Value Then

.Rows(i).Insert
With .Cells(i, "E")

.Value = "Line " & .Cells(i + 1, "F").Value
With .Font

.Name = "Arial"
.Size = 12
.Bold = True
End With
End With
End If
Next i
End With

End Sub

blntfrctrma
07-31-2009, 05:47 AM
it works well, thank you very much for the help

rbrhodes
07-31-2009, 09:13 PM
ah, but did you learn anything, grasshopper?