Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / New Users / September 2007

Tip: Looking for answers? Try searching our database.

Macro question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
jlmccabes - 26 Sep 2007 13:30 GMT
This is where I start
Act     10   12    8    30
Bud      9   12    9    30

Trying to get here
Act     10     12        8        30
%       33.3   40.0    26.7    100.0
Bud    9        12       9         30
%       30.0    40.0   30.0    100.0

Large worksheet so trying to do a macro I can manually run (CTL+q) going to
second line, insert row, calculate each number based on the total number.
Tried several times, got line to insert, calculated first value, then it
went haywire.  Not sure if should try again using the R1C1 system or not.
Small favor - please do not make it look toooooo easy.
JW - 26 Sep 2007 13:58 GMT
One way:
Asssuming that your data starts in row 2
Sub this()
   For i = Cells(Rows.Count, 1).End(xlUp).Row To 2 Step -1
       With Cells(i, 1)
           If i <> 2 Then .EntireRow.Insert shift:=xlDown
           .Offset(1, 0).Value = "%"
           .Offset(1, 1).FormulaR1C1 = "=R[-1]C/R[-1]C[3]*100"
           .Offset(1, 2).FormulaR1C1 = "=R[-1]C/R[-1]C[2]*100"
           .Offset(1, 3).FormulaR1C1 = "=R[-1]C/R[-1]C[1]*100"
           .Offset(1, 4).FormulaR1C1 = "=sum(RC[-3]:RC[-1]"
       End With
   Next i
End Sub
> This is where I start
> Act     10   12    8    30
[quoted text clipped - 11 lines]
> went haywire.  Not sure if should try again using the R1C1 system or not.
> Small favor - please do not make it look toooooo easy.
Bob Phillips - 26 Sep 2007 13:59 GMT
Public Sub ProcessData()
Dim i As Long
Dim iLastRow As Long

   With ActiveSheet

       iLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
       For i = iLastRow To 1 Step -1
           .Rows(i + 1).Insert
           .Cells(i + 1, "A").Value = "%"
           .Cells(i + 1, "B").Value = .Cells(i, "B").Value / .Cells(i,
"E").Value * 100
           .Cells(i + 1, "C").Value = .Cells(i, "C").Value / .Cells(i,
"E").Value * 100
           .Cells(i + 1, "D").Value = .Cells(i, "D").Value / .Cells(i,
"E").Value * 100
           .Cells(i + 1, "E").Value = 100
       Next i

   End With

End Sub

Signature

HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

> This is where I start
> Act     10   12    8    30
[quoted text clipped - 12 lines]
> went haywire.  Not sure if should try again using the R1C1 system or not.
> Small favor - please do not make it look toooooo easy.
Don Guillett - 26 Sep 2007 14:20 GMT
try this
Sub percentoftotal()
mc = 1
For i = Cells(Rows.Count, mc).End(xlUp).Row To 2 Step -1
'MsgBox Cells(i, mc)
For j = 1 To 4
Cells(i + 1, mc + j) = _
Format(Cells(i, mc + j) / Cells(i, mc + 4), "0.00%")
Next j
Rows(i).Insert
Next i
Rows(2).Delete
End Sub

Signature

Don Guillett
Microsoft MVP Excel
SalesAid Software
dguillett1@austin.rr.com

> This is where I start
> Act     10   12    8    30
[quoted text clipped - 12 lines]
> went haywire.  Not sure if should try again using the R1C1 system or not.
> Small favor - please do not make it look toooooo easy.
jlmccabes - 26 Sep 2007 15:06 GMT
Thank You one and ALL..  I did ask you to not make it tooo easy...  Could
have thought about it longer and made me feel better...  Just kidding...
Have to go to work - will run it tonight and extend it out for all 13
columns.  I can at least do that part with the start I have now..  Thank You
again
This is where I start
Act     10   12    8    30
Bud      9   12    9    30

Trying to get here
Act     10     12        8        30
%       33.3   40.0    26.7    100.0
Bud    9        12       9         30
%       30.0    40.0   30.0    100.0

Large worksheet so trying to do a macro I can manually run (CTL+q) going to
second line, insert row, calculate each number based on the total number.
Tried several times, got line to insert, calculated first value, then it
went haywire.  Not sure if should try again using the R1C1 system or not.
Small favor - please do not make it look toooooo easy.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.