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

Macro to transform formulas into values across multiple tabs

$
0
0
Hi everybody,

I have never written a macro and when I record one I usually have trouble with the relative references.
I am trying to write a macro to transform formulas into values every month.
I want to transform formulas:
- across a range of tabs: each tab is exactly alike and is named page-1 to page 25
- on a different column every month (same column across all tabs)
- on the same rows: L168 to L227 and L266 to L277 (same rows across all tabs)

Can anyone help?
Thanks!!

VBA Code Needed

$
0
0
Hi there,

I need VBA code to find the text "D19" in my sheet and put the below border around the entire row (columns "B:Q") where it's found.

LineStyle = xlDouble
.Color = -6279056
.TintAndShade = 0
.Weight = xlThick

My sheet is fed by Vlookup formulas so it changes everytime I open the workbook ... the code needs to be able to find my group which is D19 and border only that row not the others.

I have found code that can highlight the row, but cant find any code for bordering the row. Can this be done??

Cell conditional formatting

$
0
0
I have a cell G9 on my Excel worksheet that links to data on a hidden sheet. The data contains possible contract verbage options that are:

AIP
Standard
Implant Pass Thru
Implant Pass-Thru PPR
No Implant Pass-thru PPR

When one of these is selected, I want one of the two textboxes to grey out so no data can be entered into that textbox that corresponds with the above list. The 2 textboxes are: AB Standard which is cell B124 and Supply UB standard which is cell B125.

If the user selects AIP or Implant Pass Thru, then monetary is to be filled in Supply UB. If they selected one of the other 3, the monetary is to be filled in AB Standard. I am not sure how to use conditional formatting to code this or if I even can. I was thinking an IF statement somehow in cell B124 and B125 that says something about if cell G9 = "whatever" then enable that cell if not grey out. Just not sure how to go about doing that.

Simple first unused row problem

$
0
0
I want a macro to look at Column A starting at the first row and when it finds the first cell that is empty delete the row where is found and also delete all rows in the entire workbook below it.

It has to look at the first row and then the second row etc until it finds the blank. Doing it backwards (going up from the bottom) will not work with my data.

copy rows from one sheet to another based formula results

$
0
0
Kind of difficult to explain, but I have a report that is run weekly that shows items that have been returned over the last 3 months. The report shows the original date of purchase and the return date, but not the number of days since the purchase and the return. I need to have any items that were returned over 15 days go to a new sheet and display just those rows of information. I am not sure if this is VBA or not. Any help will be greatly appreciated.

Autofill contents - change position changes

$
0
0
Evening All.

I have tried searching on site and googling but have been unable to find anything that i can understand and manipulate to my needs.
My planned spreadsheet is every expanding and i am looking to find away to autofill formula.
So far i have the following which will find the final row of data and the select this row until column J. however i am unable to autofill down until final data in column K (changes each day)

Code:


Sub try2()
Range("A2").Select
Selection.End(xlDown).Offset(0, 0).Select

Range(Selection, Selection.End(xlToRight).Offset(0, -5)).Select
Selection.AutoFill Destination:=Range("A24:J38")

End Sub

So far i am only able to autofill when i stipulate exact range which is no good

any help / suggestions / links would be greatly appreciated as have been pulling my hair out with this one

Opening a pdf file after saving it as a pdf using VBA

$
0
0
In my macro, I was able to save the excel file as a pdf. But is there something I can add to the code to also automatically open that pdf file I just saved for verification purposes?

Below is the code I used to save the file as PDF. Pretty basic.

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
filename:=filename, _
Quality:=xlQualityMinimum


I would like to also open up this pdf file using excel VBA. Is it possible?

Shared File Causing 1004 Error

$
0
0
Hi,

I'm wondering if anyone might know, why my code would hit a run time error on a shared file? It works fine unshared. This is on a ActivateSheet Worksheet Event, Code is housed in a Module and called when activated

Code:

Private Sub Worksheet_Activate()
    Call RatingsValidations
End Sub

Code:

Sub RatingsValidations()
    Dim i As Long
    Dim c As Long
   
    Dim MDPRSelTemp
    Dim MDPRSel() As Variant
    Dim MDPRString As Variant
   
    Dim MRSelTemp
    Dim MRSel() As Variant
    Dim MRString As Variant
   
    Dim MWARFSelTemp
    Dim MWARFSel() As Variant
    Dim MWARFString As Variant
       
    Dim SPSelTemp
    Dim SPSel() As Variant
    Dim SPString As Variant
   
    Dim FitchSelTemp
    Dim FitchSel() As Variant
    Dim FitchString As Variant
   
    MDPRSelTemp = WorksheetFunction.Transpose([NotchingSelectionMDPR])
    MRSelTemp = WorksheetFunction.Transpose([NotchingSelectionMR])
    MWARFSelTemp = WorksheetFunction.Transpose([NotchingSelectionMWARF])
    SPSelTemp = WorksheetFunction.Transpose([NotchingSelectionSP])
    FitchSelTemp = WorksheetFunction.Transpose([NotchingSelectionFitch])
   
    c = 0
    For i = 1 To UBound(MDPRSelTemp)
        If MDPRSelTemp(i) <> False Then
            ReDim Preserve MDPRSel(c)
            MDPRSel(c) = MDPRSelTemp(i)
            c = c + 1
        End If
    Next
       
    c = 0
    For i = 1 To UBound(MRSelTemp)
        If MRSelTemp(i) <> False Then
            ReDim Preserve MRSel(c)
            MRSel(c) = MRSelTemp(i)
            c = c + 1
        End If
    Next
       
    c = 0
    For i = 1 To UBound(MWARFSelTemp)
        If MWARFSelTemp(i) <> False Then
            ReDim Preserve MWARFSel(c)
            MWARFSel(c) = MWARFSelTemp(i)
            c = c + 1
        End If
    Next
   
    c = 0
    For i = 1 To UBound(SPSelTemp)
        If SPSelTemp(i) <> False Then
            ReDim Preserve SPSel(c)
            SPSel(c) = SPSelTemp(i)
            c = c + 1
        End If
    Next
   
    c = 0
    For i = 1 To UBound(SPSelTemp)
        If SPSelTemp(i) <> False Then
            ReDim Preserve SPSel(c)
            SPSel(c) = SPSelTemp(i)
            c = c + 1
        End If
    Next
   

    MDPRString = Join(MDPRSel, ",")
    MRString = Join(MRSel, ",")
    MWARFString = Join(MWARFSel, ",")
    SPString = Join(SPSel, ",")
    FitchString = Join(FitchSel, ",")
   
   
    Sheet4.[ValidationMDPRSelection].Validation.Delete
    Sheet4.[ValidationMRSelection].Validation.Delete
    Sheet4.[ValidationMWARFSelection].Validation.Delete
    Sheet4.[ValidationSPSelection].Validation.Delete
   
    If MDPRString = "" Then
    Else
        Sheet4.[ValidationMDPRSelection].Validation.Add Type:=xlValidateList, Formula1:=MDPRString
    End If
       
    If MRString = "" Then
    Else
        Sheet4.[ValidationMRSelection].Validation.Add Type:=xlValidateList, Formula1:=MRString
    End If
   
    If MWARFString = "" Then
    Else
        Sheet4.[ValidationMWARFSelection].Validation.Add Type:=xlValidateList, Formula1:=MWARFString
    End If
   
    If SPString = "" Then
    Else
        Sheet4.[ValidationSPSelection].Validation.Add Type:=xlValidateList, Formula1:=SPString
    End If
 
'STATUS
    Dim MDPRStatusTemp
    Dim MDPRStatus() As Variant
    Dim MDPRString2 As Variant
   
    Dim MRStatusTemp
    Dim MRStatus() As Variant
    Dim MRString2 As Variant
   
    Dim MWARFStatusTemp
    Dim MWARFStatus() As Variant
    Dim MWARFString2 As Variant
       
    Dim SPStatusTemp
    Dim SPStatus() As Variant
    Dim SPString2 As Variant
   
    Dim FitchStatusTemp
    Dim FitchStatus() As Variant
    Dim FitchString2 As Variant
   
    MDPRStatusTemp = WorksheetFunction.Transpose([NotchStatusMDPR])
    MRStatusTemp = WorksheetFunction.Transpose([NotchStatusMR])
    MWARFStatusTemp = WorksheetFunction.Transpose([NotchStatusMWARF])
    SPStatusTemp = WorksheetFunction.Transpose([NotchStatusSP])
    FitchStatusTemp = WorksheetFunction.Transpose([NotchStatusFitch])
   
    c = 0
    For i = 1 To UBound(MDPRStatusTemp)
        If MDPRStatusTemp(i) <> False Then
            ReDim Preserve MDPRStatus(c)
            MDPRStatus(c) = MDPRStatusTemp(i)
            c = c + 1
        End If
    Next
       
    c = 0
    For i = 1 To UBound(MRStatusTemp)
        If MRStatusTemp(i) <> False Then
            ReDim Preserve MRStatus(c)
            MRStatus(c) = MRStatusTemp(i)
            c = c + 1
        End If
    Next
       
    c = 0
    For i = 1 To UBound(MWARFStatusTemp)
        If MWARFStatusTemp(i) <> False Then
            ReDim Preserve MWARFStatus(c)
            MWARFStatus(c) = MWARFStatusTemp(i)
            c = c + 1
        End If
    Next
   
    c = 0
    For i = 1 To UBound(SPStatusTemp)
        If SPStatusTemp(i) <> False Then
            ReDim Preserve SPStatus(c)
            SPStatus(c) = SPStatusTemp(i)
            c = c + 1
        End If
    Next
   
    c = 0
    For i = 1 To UBound(SPStatusTemp)
        If SPStatusTemp(i) <> False Then
            ReDim Preserve SPStatus(c)
            SPStatus(c) = SPStatusTemp(i)
            c = c + 1
        End If
    Next
   
    MDPRString2 = Join(MDPRStatus, ",")
    MRString2 = Join(MRStatus, ",")
    MWARFString2 = Join(MWARFStatus, ",")
    SPString2 = Join(SPStatus, ",")
    FitchString2 = Join(FitchStatus, ",")
   
   
    Sheet4.[ValidationMDPRStatus].Validation.Delete
    Sheet4.[ValidationMRStatus].Validation.Delete
    Sheet4.[ValidationMWARFStatus].Validation.Delete
    Sheet4.[ValidationSPStatus].Validation.Delete
   
    If MDPRString2 = "" Then
    Else
        Sheet4.[ValidationMDPRStatus].Validation.Add Type:=xlValidateList, Formula1:=MDPRString2
    End If
   
    If MRString2 = "" Then
    Else
        Sheet4.[ValidationMRStatus].Validation.Add Type:=xlValidateList, Formula1:=MRString2
    End If
   
    If MWARFString2 = "" Then
    Else
        Sheet4.[ValidationMWARFStatus].Validation.Add Type:=xlValidateList, Formula1:=MWARFString2
    End If
   
    If SPString2 = "" Then
    Else
        Sheet4.[ValidationSPStatus].Validation.Add Type:=xlValidateList, Formula1:=SPString2
    End If


End Sub

Thanks for your help in advance

input number in range

$
0
0
Hello
With the inputbox I want to insert a numeric value
to define a cell range, for example "C15:F15"

This is the code i´m using:

x = InputBox("Insert Row")
Range("C(x):F(x)").Select


Where (x) represents the Inputbox data (the number "15") I want to insert, But it doesn´t runs, anybody can help me?

Regards
Claudio

Looping through each row

$
0
0
I'm trying to get this stupid loop to do something. Sorry it's such a lame question, but I don't really know what I'm doing here. I want to do the tasks listed in each row, go to the next row, do the same tasks, and quit when column A is empty. No matter what I try I cant get it to work.

Code:

Do
      with objWorkBook.Worksheets("Sheet1").Cells(r, 1)
         
                'msgbox r
                objWorkBook.Worksheets("Sheet1").Cells(r, 1).select
                CellValue = objWorkBook.Worksheets("Sheet1").Cells(r, 1).value
                'msgbox CellValue
               
               
               
                sess0.screen.moveto 21,3
                sess0.screen.sendkeys("<Tab>DIFDI" & CellValue)
                sess0.screen.sendkeys("<Enter>")
               
                Result=sess0.screen.GetString(11, 10, 24)
                objWorkBook.WorkSheets("Sheet1").Cells(r,2).Value = Trim(Result)
               
                'msgbox Result
               
                msgbox R
                Exit Do
           
 
        End With
       
  r = r+1
 
 Loop

[SOLVED] Macro works in 2010&2013 but not Excel 2003

$
0
0
This macro works for Excel 2010 and 2013, but not
Excel 2003. When I run it in Excel 2003 all the cells
(up to row 456) gets filled with #NAMN?
I'm trying to import data from the file called laget.xls
to idrott.xls where the macro resides. I'm using the
Swedish version of Excel 2003 so I guess NAMN
means NAME in English.


Code:

Sub button_import()
'
' button_import Macro
' imports data from laget.xls
'
' Keyboard Shortcut: Ctrl+Shift+I
'

    Range("P2").Select
    Selection.End(xlToLeft).Select
    Range("A2:T506").Select
    Selection.ClearContents
    Range("A2").Select

    ActiveWindow.ScrollColumn = 6
    ActiveWindow.ScrollColumn = 5
    ActiveWindow.ScrollColumn = 4
    ActiveWindow.ScrollColumn = 1
    Range("A2").Select
    ActiveCell.FormulaR1C1 = _
        "=IFERROR(LEFT('[laget.xls]Sida 1'!RC,FIND("" "",'[laget.xls]Sida 1'!RC,1)),"""")"
    Range("C2").Select
    ActiveCell.FormulaR1C1 = _
        "=IFERROR(MID('[laget.xls]Sida 1'!RC[-2],FIND("" "",'[laget.xls]Sida 1'!RC[-2],1),(LEN('[laget.xls]Sida 1'!RC[-2])-FIND("" "",'[laget.xls]Sida 1'!RC[-2],1))+1),"""")"
    Range("D2").Select
    ActiveCell.FormulaR1C1 = _
        "=IF(RC[-3]="""","""",IF(MOD(MID('[laget.xls]Sida 1'!RC[-1],LEN('[laget.xls]Sida 1'!RC[-1])-1,1),2)=0,""Kvinna"",""Man""))"
    Range("F2").Select
    ActiveCell.FormulaR1C1 = _
        "=IFERROR(IF('[laget.xls]Sida 1'!RC[-3]=0,"""",'[laget.xls]Sida 1'!RC[-3]),"""")"
    Range("H2").Select
    ActiveCell.FormulaR1C1 = _
        "=IFERROR(IF('[laget.xls]Sida 1'!RC=0,"""",'[laget.xls]Sida 1'!RC),"""")"
    Range("I2").Select
    ActiveCell.FormulaR1C1 = _
        "=IFERROR(IF('[laget.xls]Sida 1'!RC=0,"""",'[laget.xls]Sida 1'!RC),"""")"
    Range("J2").Select
    ActiveCell.FormulaR1C1 = _
        "=IFERROR(IF('[laget.xls]Sida 1'!RC=0,"""",'[laget.xls]Sida 1'!RC),"""")"
    Range("K2").Select
    ActiveCell.FormulaR1C1 = "=IF(RC[-10]="""","""",""Sverige"")"
    Range("L2").Select
    ActiveCell.FormulaR1C1 = _
        "=IFERROR(IF('[laget.xls]Sida 1'!RC[-7]=0,"""",'[laget.xls]Sida 1'!RC[-7]),"""")"
    Range("M2").Select
    ActiveCell.FormulaR1C1 = _
        "=IFERROR(IF('[laget.xls]Sida 1'!RC[-7]=0,"""",'[laget.xls]Sida 1'!RC[-7]),"""")"
    Range("N2").Select
    ActiveCell.FormulaR1C1 = _
        "=IFERROR(IF('[laget.xls]Sida 1'!RC[-7]=0,"""",'[laget.xls]Sida 1'!RC[-7]),"""")"
    Range("P2").Select
    ActiveCell.FormulaR1C1 = _
        "=IFERROR(IF('[laget.xls]Sida 1'!RC[-12]=0,"""",'[laget.xls]Sida 1'!RC[-12]),"""")"
    Range("Q3").Select
    Selection.End(xlToLeft).Select
    Selection.End(xlToLeft).Select
    Range("A2:T456").Select
    Selection.FillDown
    ActiveWindow.ScrollRow = 429
    ActiveWindow.ScrollRow = 422
    ActiveWindow.ScrollRow = 402
    ActiveWindow.ScrollRow = 357
    ActiveWindow.ScrollRow = 355
    ActiveWindow.ScrollRow = 352
    ActiveWindow.ScrollRow = 341
    ActiveWindow.ScrollRow = 201
    ActiveWindow.ScrollRow = 194
    ActiveWindow.ScrollRow = 192
    ActiveWindow.ScrollRow = 191
    ActiveWindow.ScrollRow = 88
    ActiveWindow.ScrollRow = 42
    ActiveWindow.ScrollRow = 31
    ActiveWindow.ScrollRow = 18
    ActiveWindow.ScrollRow = 10
    ActiveWindow.ScrollRow = 2
    ActiveWindow.ScrollRow = 1
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Application.CutCopyMode = False
    Range("A2").Select
End Sub

Monitoring Actions

$
0
0
Hi All,

Is there any vb code or a macro to monitor the activities of the user to track all the actions what all he had done in a excel.

Data Validation - Change Event help needed.

$
0
0
Dear all,

Regarding Data Validation.

I have two columns of Data. See Grades and Names columns.

Data Validation for Grades List and Names List

I need your help to Code the following scenario:
* If Grade is changed, then Name List should get empty.
*After Selecting Name List, then we shouldn't allow to change the Grade.

PFA for reference.

Thanks,
Vinod Krishna

VBA Code for Exporting Selected Columns in Excel to Notepad

$
0
0
Upon clicking a button, columns A -D will be copied to notepad. In the notepad, there should be additional items added on top of the values copied from Excel.

Sample template of both excel and notepad as attached. Would greatly appreciate if anyone could set up the VBA codes or at least guide me on how I should start. Thanks.

Sample1.xlsxSample1.txt

Set initial Userforml font size through Properties Window instead of code

$
0
0
Instead of coding it (like below), can you set it in the properties window for labels, buttons.. etc.

Code:

Sub OpenForm()
    UserForm1.Label2.Font.Size = 12
    UserForm1.Show
End Sub


Problem while generating vloop in excel using vb 6.0

$
0
0
my actual code

ws.Range("D5:D7").Value = "=VLOOKUP(RC[-1],TG!A:C,2,FALSE)"

Output in Excel worksheet

Cell Value

D5 =VLOOKUP(C5,TG!A:D:D,2,FALSE)
D6 =VLOOKUP(C6,TG!A:D:D,2,FALSE)
D7 =VLOOKUP(C7,TG!A:D:D,2,FALSE)


Plz help me to solve this case.... :-)

Find & Replace

$
0
0
Hi, Please have look on code. I need to do small task. From A2, replace all “1”s with “PMAH” and all others with “NON- PMAH”. Column has header that’s why I taken from A2. I am able to do with “1” replace to “PMAH” but mind is not working regarding “NON-PMAH”. Plz advise.

Code:

Sub FindReplace()

Dim a As Range

With ActiveSheet

For Each a In .Range(.Range("A2"), .Range("A2").End(xlDown))

a = Replace(a, "1", "PMAH")
Next
End With

End Sub

[SOLVED] Calculate Calls per hour

$
0
0
I receive call data daily and need to be able to calculate the number of calls per hour by center phone number.

I have attached a sample report (Report tab) and want to enter the results on the CPH tab. On the Report tab, I use column B (Answer Time) for the time the call is received and Column G (center) as the location and populate the results on the CPH tab. Any blanks in column B should be ignored in the calculation.

Thank you for your help.
Attached Files

Select sheets in workbook then consolidate data

$
0
0
Hi friends,

* I have a workbook, with different sheets (with sheet name as Home, RawData, Data1, Data2, Data3, ...), these sheets are not fixed
* FYI... sheet (home) has a VBA code which on running creates a new sheet and pull data from some other source (So the sheet number is not fixed in the workbook, but the newly added sheet is named in a specific format as Data1, Data2, Data3, ...)
* So we can say, that the sheet number and name are not fixed (It keeps on changing)
* All these sheets have data in the same format starting from range A2:J2, except sheet(home)

Two things i am trying to do:-
- Select sheets from the workbook (to be consolidated)
- Consolidate selected sheets in a new sheet

Here is the sample file Select sheet then consolidate.xlsm


Thanks & regards,
Manish

Consolidate Data withot Losing Other Columns

$
0
0
Hello,
I am having trouble consolidating a worksheet by 2 columns but keeping the data in all the other columns once the consolidation is complete. I would like to write a code that tells excel to look in column B (PSD ID) and when it finds duplicates sum the values in column S (Gaining Doc Matched Quantity). I know how to do this when it is just those two columns but I would like to be able to consolidate the sheet so that I can keep the data in all the other columns. For my purposes, I don't care which row excel choses to pull data from in regards to the other columns when it is doing this consolidation. All I care about is that Column S and that it is summed. I've attached a sample doc that shows what the data looks like in the beginning and what I would like it to look like in the end. I guess I could do a vlookup function for all my other columns but I figure there has to be a more efficient way. If someone could help with getting the vlookup to work for column A I would appreciate it as well. Thanks in advance for the help.

Consolidation Problem.xlsx
Viewing all 50103 articles
Browse latest View live