Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all 50085 articles
Browse latest View live

Creating a button to save an output value

$
0
0
Hi I have a bonus calculator sheet that I would like some help with. I apologize in advance as I do not know VB at all but I can copy paste code! :)

My sheet has a calculator that outputs a value based on inputs. I also have a pick list on top labeled Q1-Q4. Depending on which value is selected on the picklist, the input values will output a different amount. I want to create a button which allows me to take this output and save it in another cell under a heading Q1, Q2 etc. depending on which Q was selected in the original picklist. In essence I want a button that records each output onto the same sheet by by quarter(Q).

Thanks!

Copy from master sheet to sub sheets based on date

$
0
0
I am trying to automate a copy process. The master sheet in the Excel file is a daily log that I need to report detail from Monthly and Quarterly. I need data to copy each row to appropriate Monthly tab based on picking up the month from the detail keyed in to column K in master sheet. Master sheet is titled Master Tab and the monthly sheets are titled Jan '14, Feb '14.... The current format of the date in Column K is x/xx/xx. All data that is keyed into Columns A thru P need to copy to new row in appropriate month tab. I have very little background in writing the code. Can anyone help me please? Thank you!

Quadratic Formula help in vba

$
0
0
Hi Experts,

I need some help to fix my Quadratic Equation in VBA. It looks fine except sqrt part.

Here is the normal equation below X =

-b +- √b^2-4(a)(c)
---------------------
2(a)


Here is my b value

b = (Range("C13") * Range("C14") / Range("C14") + vt * (xf - 1)

Based on B my equation looks like this

X = - Range("C13") * Range("C14") / Range("C14") + vt * (xf - 1) - Sqr(Range("C13") * Range("C14") / Range("C14") + vt) * (xf - 1) ^ 2 - 4 * ksp / 2


It would be great if someone can give an idea on sqrt part. Beside that all seems to be working.

Thanks,
Vik

[SOLVED] Sheet code is not working for grade

$
0
0
Hi friends,
I'm not getting grade in column 'AS'. It's based on the marks In column 'AR' which are getting by formula.

Please see the attachment and suggest me a correction.

Thanking you In anticipation.

Sincerely,

Mukesh
Attached Files

Position shapes text boxes per listing on sheet to another sheet

$
0
0
I have the following code to copy and paste shapes text boxes into specific location on a worksheet

Code:

Set WS = Worksheets("Planning")
Set ws1 = Worksheets("Data")

    With ws1.Shapes("PartData_RevA")
        .Copy
    End With
       
    With WS
        .Paste
    End With
           
    With WS.Shapes("PartData_RevA")
        .Left = 187
        .Top = 365
        .Height = 296
        .Width = 177
    End With
   
    With ws1.Shapes("MeasureData_RevA")
        .Copy
    End With
       
    With WS
        .Paste
    End With
           
    With WS.Shapes("MeasureData_RevA")
        .Left = 372
        .Top = 547
        .Height = 99
        .Width = 177
    End With

Firstly the code is somewhat messy, any suggestions on how to possibly tidy up, or better yet....... the second option below would be more appropriate.

Secondly, have a table on another sheet (sheet named "TextBoxes") that details the Shapes Text Box names and the respective left, top, height and width parameters. I thought that some type of routine that would go to the sheet "TextBoxes" and cylce thru all the entries and copy from sheet "Data" and paste to the sheet "Planning" in the corresponding location detailed in the sheet "TextBoxes". The data range for text box name, left, top, height and width are in columns A thru E respectively, with row one reserved to headings.

Any help would be greatly appreciated.

Thanks:confused:

VBA to speed up

$
0
0
Hi,

My below code when runs, screen stucks and take sometime. Data is filled till less then 200 rows. Anyway I can speed it up?

Code:

Sheets("Dump").Select
Dim rngAddress As Range
  Set rngAddress = Range("A1:AZ1").Find("Primary Owner First Name")
  If rngAddress Is Nothing Then
    MsgBox "Primary Owner First Name column was not found."
    Exit Sub
  End If
  Range(rngAddress, rngAddress.End(xlDown)).Select
      Selection.Cut
    Columns("A:A").Select
    Selection.Insert Shift:=xlToRight

Thanks,
Shiva

Finding Missing Dates In a Column of Dates

$
0
0
I have been requested to find the date range which my ads have been running. The only way in which I can get the raw data is to have the data broken out by date for each day of my date range (7/1/2013-2/28/2014). This is not ideal, but it's the only way I have the data. The problem I need to solve is how to determine the dates when the ad was not active (i.e. the missing dates in the list), and the end result needs to be me giving a date range for when each ad was active.

For example, if the ad has a list of dates from 7/1/2013-7/10/2013, and the list is missing 7/6/2013, I need the following end result for that ad:
7/1/2013-7/5/2013; 7/7/2013-7/10/2013

My first instinct was to create a macro using a formula to give me the missing dates and pass each ad and its list of dates into a tab with that formula, it populates the missing dates, then it gets pasted into an output tab with the missing dates transposed so it all ends up and one row. The macro then loops (loop not added to macro yet) to run through the entire list. This may not be the optimal method, but the attached document has the beginnings of this macro in it. I had trouble with getting the macro to run through the list due to issues with copy/pasting/deleting, so it may be useless.

I appreciate any insight/help or recommendations on other methods to get this accomplished. Again, the 'Data' tab shows each ad (it's a jumble, but makes sense to my needs so ignore how odd the ads look) with its list of dates and I am looking for the missing dates + compiling it into a date range of time without those missing dates.
Attached Files

[SOLVED] VBA functions

$
0
0
Hi,
I am having problems starting my very first vba function.
Firstly I saved the uploaded document as a macro enabled workbook and also enabled developer.
However I am not getting my vba to work.


Pls download the attachment and do the 2 above steps to assist me.
Here is the question:
Cell C2 has the exchange rate for US$ to TT$. In the appropriate code module in this workbook, write a
VBA procedure with an appropriate name that would be used to calculate the equivalent TT Cost of the
cars (Cells C4 to C13) when the Cost in US$ and exchange rate are provided as arguments. Use this
formula for C4, then use the Fill handle, (using the user-created procedure) to copy the formula to the
range C5:C13.



This is my created vba:
Code:

Function CONVERTTOTT (x As Currency, y As Currency)

CONVERTTOTT = Round ((x+y), 2)
End Function

and in the excel vehicles, sheet 1, c4:
=CONVERTTOTT(B4,C2)
Attached Files

Hide worksheets based on tab color

$
0
0
Hi

Found a closed post on a solution that is almost what I am looking for, described by the following tab layout...

All tabs in worksheet: Master1, Tab1, Tab2, Master2, Tab3, Tab4, Master3, Tab5, Tab6

Click Master1: Visible - Master1, Tab1, Tab2, Master2, Master3
Click Master2: Visible - Master1, Master2, Tab3, Tab4, Master3
Click Master3: Visible - Master1, Master2, Master3, Tab5, Tab6

When you click a master tab, all tabs that are NOT the same color as that Master are hidden (except other masters)

This bit of VBA does the trick however I would like it to be color based. In this model below, you have to manually add the worksheets that belong to a particular master.

The behavior I seek is to associate a worksheet with a master by changing its tab color, and not having to do it in the code. I think it could be accomplished by cycling through the workbook and creating an array of tabs based on tab color, alas I am a total VBA noob...any help would be greatly appreciated.


'=============>>
Private Sub Worksheet_Activate()
Dim sh As Worksheet 'Object
Dim arr As Variant

arr = Array("Sheet1", "Sheet2", "Sheet3") ' <<=== CHANGE

On Error GoTo XIT
With Application
.EnableEvents = False
.ScreenUpdating = False
End With

For Each sh In ThisWorkbook.Sheets
If Not sh.Name Like "Master*" Then
sh.Visible = xlSheetHidden
End If
Next sh

For Each sh In Sheets(arr)
sh.Visible = xlSheetVisible
Next sh

XIT:
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
End Sub

'-------------------------->>

Private Sub Worksheet_Deactivate()
Dim sh As Worksheet
Dim arr As Variant

arr = Array("Sheet1", "Sheet2", "Sheet3") ' <<=== CHANGE

On Error GoTo XIT
With Application
.EnableEvents = False
.ScreenUpdating = False
End With

For Each sh In Sheets(arr)
sh.Visible = xlSheetVisible
Next sh

XIT:
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
End Sub
'<<=============

[SOLVED] Code failing to detect a null MsgBox value

$
0
0
Hey Guys,

My code is below...

Code:

Sub YrMonth()
    Dim myMonth As Variant

    ' Set Counter
    Counter = 0
   
    ' Ask for Month
    Do
        myMonth = InputBox("Month")
        Counter = Counter + 1
        If Not myMonth Then
            If Counter = 5 Then
                MsgBox "You failed to set the month to use, Macro cannot proceed further. Please remember that " & ActiveWorkbook.Name & " has been modified.", vbExclamation, "Macro interupted"
                Exit Sub
            End If
        End If
    Loop Until myMonth
End Sub

Why doesn't this work, it errors out on If Not myMonth Then

Any ideas?

Combine several workbooks containing data in multiple sheets into a master Workbook

$
0
0
I am trying to combine several workbooks containing data in multiple sheets into a master workbook. All the workbooks have the same number of worksheets. I would like to combine all data in Sheet1 into a new Sheet1, all data from Sheet2 into a new Sheet2, etc.

Can anyone help me with the code for this?

Thanks!

How can I sort a range by cell color

$
0
0
Hi All,
I have a spreadsheet we use as a "Stock Location guide" and the critical colums are as follows, Column A = Location, Column B = Date and Column F = Material Description. The following code is what we have been using to sort the guide in order of F, B and then A :
Code:

Sub Sort_Location()
'
    Application.CutCopyMode = False
    Selection.Sort Key1:=Range("F2"), Order1:=xlAscending, Key2:=Range("B2") _
        , Order2:=xlAscending, Key3:=Range("A2"), Order3:=xlAscending, Header:= _
        xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
   
End Sub

What we want to do is swap "A" and "B" so "A" is sorted before "B" and also to change the way"A" is sorted. Certain cells in "A" are yellow and I want to be able to sort by Cell color with yellow on top.
Any help would be greatly appreciated.
Cheers Gunner222

Need hidden range to "move" when rows are added or deleted....I'm close but no cigar.

$
0
0
Good evening. I've created a form to track various staffing info and patterns that will be updated on a regular basis. I'm including a date and number "calculator" to assist the user when updating the form. The first two sheets are similar but for different programs. The third sheet has info I'm referencing (data validation) on the first two sheets.

When I started the form I attempted to build the "calculator" in a userform but I got in over my head really quickly so I opted to build it in the worksheets. Everything works as expected unless I "hide" the range name I've given to the calculators on sheets1 and sheets2. I wish to give the user the option to hide calculator when it's not in use, otherwise I would be all set.

So, the code I'm using to hide/show the "calculator" on sheets1 and sheets2 is listed below:

Code:

Sub RCSCalc_Click()
    Dim Rng As Range
    Dim MyCell As Range
    Set Rng = Range("IHSS_CALC")
    For Each MyCell In Rng
        If MyCell.Value = "" Then
            MyCell.EntireRow.Hidden = ActiveSheet.CheckBoxes(Application.Caller).Value = xlOn
        End If
    Next MyCell
End Sub

Sub HCTCalc_Click()
    Dim Rng As Range
    Dim MyCell As Range
    Set Rng = Range("HCT_Calc")
    For Each MyCell In Rng
        If MyCell.Value = "" Then
            MyCell.EntireRow.Hidden = ActiveSheet.CheckBoxes(Application.Caller).Value = xlOn
        End If
    Next MyCell
End Sub

Questions:

1) Would the userform route be cleaner and more efficient?
2) What am I missing in my code that would allow the named range (i.e. my "calculator") to move up or down when I add or delete rows?

Thanks for weighing in with your thoughts and suggestions.

P.S. I've attached the latest version of the form I'm working on. The password, if needed, is "j". Thanks.

Matthew
Attached Files

Copy specific cell with data from one Worksheet to the next row in another works

$
0
0
I am using the code below to copy certain cells with data from one worksheet to another worksheet next row down but the code fails at CopyRange.copy and I am not sure why. I also need this to loop I will be assigning this macro to a button.

Code:


Dim CopyRange As Range, NextCell As Range
   
    Set CopyRange = Sheet2.Range("A2:C2,D12:H12")
    Set NextCell = Sheet3.Cells(Cells.Rows.Count, 1).End(xlUp).Offset(1, 0)
   
      CopyRange.Copy
    NextCell.PasteSpecial (xlValues)
    Application.CutCopyMode = False

Sort columns ignoring blank cells

$
0
0
Hello,

Can someone pls assist me in providing a macro that is able to sort a column and ignore all blank cells in that column? I have noticed many macros I've tested allow the blank cells to go to the top of the column after it has been sorted. As such, several criteria would need to be addressed:


1) There are a total of 20 columns on the worksheet that would need to be linked to the sorting being done in one column (column T).

2) The sort in column T would start from cell T8 until T5000 and would be sorted in descending order.

3) Most importantly, the sort must ignore blank cells and allocate them below the last data entry in column T. The blank cells will have formulas embedded in them.

I've reviewed many macros currently available that purport to ignore the blank cells but not one has worked. My suspicion is that they are failing because even though the cells are blank, they have formulas embedded in them.

Thank you in advance.

Parsing/Separating Excel Worksheet into Multiple Output Files

$
0
0
I'm trying to separate the contents of an excel worksheet into several files for easier processing. What I have is a worksheet with information in several columns. The output files need to have contents of say:

1st file) Columns A + B + C + D
2nd file) Columns A + E + F + G
3rd file) Columns A + H + I + J

Column A information need to be attached to this grouping or output files all the time..Really appreciate all your inputs on this

VBA Macro not upwards compatible from Excel 2007 to Excel 2010

$
0
0
Have an Excel 2007 Macro that I have not converted from Excel 2007 to Excel 2010 because it is not upwards compatible. I tested it in 2010 and I get all kinds of VBA coding errors but it works fine in 2007. How do I resolve these coding errors. Has anyone else come across this problem. We cannot move to 2010 until I resolve this problem. Any advise would be very helpful.

[SOLVED] macro wont read copied cells unless retyped into cell

$
0
0
Hi guys I have a macro that copies time cells from another sheet and puts them in cells in another sheet, I also have another macro that takes 30 mins away from that time if a certain condition is reached but it wont work unless i retype over the copied cell , need help guys

Code to search and replace formulas

$
0
0
Hi all, I'm hoping someone can offer some support here on a lot of cells on a sheet that I need to alter the formula for.

Example is in Cell A1 I have
Formula:
='Data'!F4
so what I want is a code that will search and replace the numerical part of the data and change it to that number plus 300 so it would change to
Formula:
='Data'!F304
I am needing to do this for a lot of cells, and the layout means that dragging etc doesn't work and manual entry is going to take me a long time to do. But all cells need to have the 300 cells added to them.

Thanks in advance if anyone can help.

John

Hide multiple command buttons if cells are blank

$
0
0
I am in DIRE need of help - I've been working on this for a few days now and I can't figure it out (and I'm on a bit of a deadline) - so I'm hoping someone here can help before I pull my hair out (or worse!!)

I have formulas in each cell (E92:T92) & below each of those cells I have a command button, that when clicked, will pop up a message box displaying the result of the formula in the cell above it.

Picture1.jpg

(the formulas are performing a vlookup on a cell whose value will change based on the pivot table above and how it has been filtered)

Picture3.jpg

If the formula in the cell above the command button results in a blank, I want the command button to be hidden or invisible. I've gotten it to work with on the first command button (commandbutton2) with the code below, but the rest of the command buttons are still showing - what am I missing????

Code:

Private Sub CommandButton2_Click()

    MsgBox Range("E92").Value
   
End Sub

Private Sub CommandButton3_Click()

    MsgBox Range("F92").Value
   
End Sub

Private Sub CommandButton4_Click()

    MsgBox Range("G92").Value
   
End Sub

Private Sub CommandButton5_Click()

    MsgBox Range("H92").Value
   
End Sub

Private Sub CommandButton6_Click()

    MsgBox Range("I92").Value
   
End Sub

Private Sub CommandButton7_Click()

    MsgBox Range("J92").Value
   
End Sub

Private Sub CommandButton8_Click()

    MsgBox Range("K92").Value
   
End Sub

Private Sub CommandButton9_Click()

    MsgBox Range("L92").Value
   
End Sub

Private Sub CommandButton10_Click()

    MsgBox Range("M92").Value
   
End Sub

Private Sub CommandButton11_Click()

    MsgBox Range("N92").Value
   
End Sub

Private Sub CommandButton12_Click()

    MsgBox Range("O92").Value
   
End Sub

Private Sub CommandButton13_Click()

    MsgBox Range("P92").Value
   
End Sub

Private Sub CommandButton14_Click()

    MsgBox Range("Q92").Value
   
End Sub

Private Sub CommandButton15_Click()

    MsgBox Range("R92").Value
   
End Sub

Private Sub CommandButton16_Click()

    MsgBox Range("S92").Value
   
End Sub

Private Sub CommandButton17_Click()

    MsgBox Range("T92").Value
   
End Sub


Private Sub Worksheet_Calculate()

If [E92] <> "" Then
  CommandButton2.Visible = True
Else: CommandButton2.Visible = False
End If

If [F92] <> "" Then
  CommandButton3.Visible = True
Else: CommandButton3.Visible = False
End If

If [G92] <> "" Then
  CommandButton4.Visible = True
Else: CommandButton4.Visible = False
End If

If [H92] <> "" Then
  CommandButton5.Visible = True
Else: CommandButton5.Visible = False
End If

If [I92] <> "" Then
  CommandButton6.Visible = True
Else: CommandButton6.Visible = False
End If

If [J92] <> "" Then
  CommandButton7.Visible = True
Else: CommandButton7.Visible = False
End If

If [K92] <> "" Then
  CommandButton8.Visible = True
Else: CommandButton8.Visible = False
End If

If [L92] <> "" Then
  CommandButton9.Visible = True
Else: CommandButton9.Visible = False
End If

If [M92] <> "" Then
  CommandButton10.Visible = True
Else: CommandButton10.Visible = False
End If

If [N92] <> "" Then
  CommandButton11.Visible = True
Else: CommandButton11.Visible = False
End If

If [O92] <> "" Then
  CommandButton12.Visible = True
Else: CommandButton12.Visible = False
End If

If [P92] <> "" Then
  CommandButton13.Visible = True
Else: CommandButton13.Visible = False
End If

If [Q92] <> "" Then
  CommandButton14.Visible = True
Else: CommandButton14.Visible = False
End If

If [R92] <> "" Then
  CommandButton15.Visible = True
Else: CommandButton15.Visible = False
End If

If [S92] <> "" Then
  CommandButton16.Visible = True
Else: CommandButton16.Visible = False
End If

If [T92] <> "" Then
  CommandButton17.Visible = True
Else: CommandButton17.Visible = False
End If

End Sub

Viewing all 50085 articles
Browse latest View live