Re: Macro changing values of various cells
Hi,
Sheet: G&I
Macro: ShowFrom2
That is the macro that you pick a security in row A and click on it and then run the macro.
Thank you,
Guy
Re: Macro changing values of various cells
Hi,
Sheet: G&I
Macro: ShowFrom2
That is the macro that you pick a security in row A and click on it and then run the macro.
Thank you,
Guy
Re: Macro changing values of various cells
I tried reducing the size WAY too big no matter what I did. Look at your e-mail (thru this site). I sent you a link.
Guy
Re: Comparing Dates using if then
Dave, worked like a charm. Thanks!
Re: Macro changing values of various cells
"You state that the macro is supposed to only affect only the cells in the active row but your example says the active cell is A20 but you're pulling dat from row 17?????"
I meant Column 17 - and the row is where MOST of the data change happens. It actually changes a few different cells around. When I start the macro it can be from any row from 1 to 100. Various cells on that row are changed plus a few cells that are fixed (meaning no matter where I start the macro from the fixed cells will always be changed).
How do I post the workbook?
I have the following code that looks for a blank cell in a specific set of cells then picks the cell under it and proceeds with a macro. Note that I have multiple if/then statements. I would like to have each result of the if/then to be picking the right blank cell then proceeding with the pastes but I don't want to have to past the guts of the macro under each if/then. Is there a way to make each if/then refer to the guts of macro so I don't have to duplicate the exact macro. Damn I'm confused... Check out my notes.
Help.
Guy
Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
'Unhide All rows
Set b = Selection
ad = b.Address
Rows("3:200").Select
Selection.EntireRow.Hidden = False
Range(ad).Select
Dim firstBlank As Range
UserForm1.Hide
If ComboBox8.Value = "Consumer Discretionary" Then
Set firstBlank = Range("A4").End(xlDown).Offset(1, 0)
firstBlank.Select
ElseIf ComboBox8.Value = "Consumer Staples" Then
Set firstBlank = Range("A16").End(xlDown).Offset(1, 0)
firstBlank.Select
ElseIf ComboBox8.Value = "Energy" Then
Set firstBlank = Range("A28").End(xlDown).Offset(1, 0)
firstBlank.Select
ElseIf ComboBox8.Value = "Financials" Then
Set firstBlank = Range("A40").End(xlDown).Offset(1, 0)
firstBlank.Select
End If
' This is the guts of the macro I want to run after each of the if/then is True and after it "firstBlank.Select". Do I have to paste this in after every "firstBlank.Select" or is there a way I can refer to it??
Set b = Selection
ad = b.Address
ActiveCell = TextBox1.Value
ActiveCell.Offset(ColumnOffset:=1).Select
ActiveCell = TextBox2.Value
ActiveCell.Offset(ColumnOffset:=1).Select
ActiveCell = TextBox3.Value
ActiveCell.Offset(ColumnOffset:=1).Select
ActiveCell = ComboBox2.Value
ActiveCell.Offset(ColumnOffset:=1).Select
ActiveCell = ComboBox3.Value
ActiveCell.Offset(ColumnOffset:=1).Select
ActiveCell = ComboBox4.Value
ActiveCell.Offset(ColumnOffset:=1).Select
ActiveCell = ComboBox5.Value
ActiveCell.Offset(ColumnOffset:=1).Select
ActiveCell = ComboBox6.Value
ActiveCell.Offset(ColumnOffset:=1).Select
ActiveCell = ComboBox7.Value
ActiveCell.Offset(ColumnOffset:=7).Select
ActiveCell = ComboBox1.Value
ActiveCell.Offset(ColumnOffset:=1).Select
ActiveCell = TextBox6.Value / 100
ActiveCell.Offset(ColumnOffset:=3).Select
ActiveCell = TextBox4.Value
ActiveCell.Offset(ColumnOffset:=1).Select
ActiveCell = TextBox5.Value
ActiveCell.Offset(ColumnOffset:=1).Select
ActiveCell = TextBox7.Value
'Adding info to Tran Tab
Sheets("G&I Trans").Select
Rows("3:3").Select
Selection.Copy
Rows("4:4").Select
Selection.Insert Shift:=xlDown
Range("A4").Select
ActiveCell = "Purchase"
Range("B4").Select
ActiveCell = TextBox5.Value
ActiveCell.Offset(ColumnOffset:=2).Select
ActiveCell = TextBox1.Value
ActiveCell.Offset(ColumnOffset:=1).Select
ActiveCell = TextBox4.Value
Sheets("G&I").Select
ActiveCell.Offset(ColumnOffset:=1).Select
Selection.Copy
Sheets("G&I Trans").Select
Range("G4").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("G&I").Select
'Adjusting Cash % in Portfolio
Range("Q158").Value = Range("Q158").Value - TextBox6.Value / 100
'Adjusting Cash $ Basis
If IsNumeric(TextBox7.Value) Then
Range("V158").Value = Range("V158").Value - TextBox7.Value
End If
'Clear All Values after doing macro
TextBox1.Value = ""
TextBox2.Value = ""
TextBox3.Value = ""
TextBox4.Value = ""
TextBox5.Value = ""
TextBox6.Value = ""
TextBox7.Value = ""
ComboBox1.Value = ""
ComboBox2.Value = ""
ComboBox3.Value = ""
ComboBox4.Value = ""
ComboBox5.Value = ""
ComboBox6.Value = ""
ComboBox7.Value = ""
Sheets("G&I").Select
Range(ad).Select
'Hide All
Dim area As Range
Set area = Range([A1].End(xlDown), [A65536].End(xlUp))
On Error Resume Next
Set area = area.SpecialCells(4)
If Err = 0 Then
area.EntireRow.Hidden = True
Else
MsgBox "No blanks"
End If
Set area = Nothing
Application.ScreenUpdating = False
End Sub
Display More
Let me start off by saying I am trying to self learn VB for excel (read, I am an idiot). Ok, now, I have a spreadsheet where the macro is supposed to change a bunch of values and clear a bunch of cells based on what is entered in a form. Here is the following code I have written (hacked)
Private Sub CommandButton1_Click()
'This is FORM2 - Sell a security.
Set b = Selection
ad = b.Address
Application.ScreenUpdating = False
UserForm2.Hide
ActiveCell.Offset(ColumnOffset:=16).Select
ActiveCell = portallocation
ActiveCell.Offset(ColumnOffset:=7).Select
ActiveCell = securityvalue
cashallocation = Range("Q158").Select
cashvalue = Range("V158").Select
'Adjusting Cash in Basis
Range("V158").Value = cashvalue + (securityvalue * TextBox3.Value)
'Adjusting Portfolio Allocation
Range("Q53").Value = cashallocation - ((TextBox3.Value / 100) * Range("Q53").Value)
'Adjusting Cash Allocation
Range("Q158").Value = portallocation + ((TextBox3.Value / 100) * Range("Q53").Value)
'Removing security from Growth & Income page only if the percentage is 100% removal.
'It is not 100% then go to end of End If statement
Range(ad).Select
If TextBox3.Value = "100" Then
Selection.ClearContents
ActiveCell.Offset(ColumnOffset:=1).Select
Selection.ClearContents
ActiveCell.Offset(ColumnOffset:=1).Select
Selection.ClearContents
ActiveCell.Offset(ColumnOffset:=1).Select
Selection.ClearContents
ActiveCell.Offset(ColumnOffset:=1).Select
Selection.ClearContents
ActiveCell.Offset(ColumnOffset:=1).Select
Selection.ClearContents
ActiveCell.Offset(ColumnOffset:=1).Select
Selection.ClearContents
ActiveCell.Offset(ColumnOffset:=1).Select
Selection.ClearContents
ActiveCell.Offset(ColumnOffset:=1).Select
Selection.ClearContents
ActiveCell.Offset(ColumnOffset:=7).Select
Selection.ClearContents
ActiveCell.Offset(ColumnOffset:=1).Select
Selection.ClearContents
ActiveCell.Offset(ColumnOffset:=3).Select
Selection.ClearContents
ActiveCell.Offset(ColumnOffset:=1).Select
Selection.ClearContents
ActiveCell.Offset(ColumnOffset:=1).Select
Selection.ClearContents
End If
'Add to Transactions
'All Changes do this
Sheets("G&I Trans").Select
Rows("3:3").Select
Selection.Copy
Rows("4:4").Select
Selection.Insert Shift:=xlDown
Sheets("G&I").Select
Selection.Copy
Sheets("G&I Trans").Select
Range("D4").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("A4").Select
ActiveCell = "Sale"
Range("F4").Select
ActiveCell = TextBox1.Value
Range("C4").Select
ActiveCell = TextBox2.Value
Sheets("G&I").Select
ActiveCell.Offset(ColumnOffset:=19).Select
Selection.Copy
Sheets("G&I Trans").Select
Range("E4").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("G&I").Select
ActiveCell.Offset(ColumnOffset:=3).Select
Selection.Copy
Sheets("G&I Trans").Select
Range("G4").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
TextBox1.Value = ""
TextBox2.Value = ""
TextBox3.Value = ""
Sheets("G&I").Select
Range(ad).Select
Application.ScreenUpdating = True
End Sub
Private Sub UserForm_Initialize()
TextBox2 = Date
End Sub
Private Sub CommandButton2_Click()
UserForm2.Hide
TextBox1.Value = ""
TextBox2.Value = ""
TextBox3.Value = ""
End Sub
Display More
in this area I am trying to take existing numbers and update them from numbers on the form but it isn't working:
ActiveCell.Offset(ColumnOffset:=16).Select
ActiveCell = portallocation
ActiveCell.Offset(ColumnOffset:=7).Select
ActiveCell = securityvalue
cashallocation = Range("Q158").Select
cashvalue = Range("V158").Select
'Adjusting Cash in Basis
Range("V158").Value = cashvalue + (securityvalue * TextBox3.Value)
'Adjusting Portfolio Allocation
Range("Q53").Value = cashallocation - ((TextBox3.Value / 100) * Range("Q53").Value)
'Adjusting Cash Allocation
Range("Q158").Value = portallocation + ((TextBox3.Value / 100) * Range("Q53").Value)
Note that what I am trying to do is start the macro from any row in column A. This macro can be started from A1 to A100 and it is supposed to effect only cells in that row. So if I started this macro on A20 I would want this code to go over to A17 and make a variable called 'portallocation'=Q17's current value. What am I doing wrong?
ActiveCell.Offset(ColumnOffset:=16).Select
ActiveCell = portallocation
The same with this next code which I want it to go over seven more columns and make the variable 'securityvalue'=X17
ActiveCell.Offset(ColumnOffset:=7).Select
ActiveCell = securityvalue
I think there are many other problems with this macro as it keeps getting jammed.
Any advice is much appreciated.
Guy
I am looking to add an if/then to the begining of a script I have that will basically look at todays's date and will run the script only if this date is the day after a date that is contained in cell A1 on my spread sheet Worksheet "Mainsheet". How would I right this? Is this possible?
Much appreciated,
Guy
How do I have the default in a texbox in a VB form default to the current date?
=Now() simply just displays "=Now()" in that form
Thanks,
Guy Gadois