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

[SOLVED] Writing =IF(ISBLANK($H4), "", VLOOKUP($H4,DCID[#All], 3, FALSE)) to a cell and work

$
0
0
I have some cells that pull info using the VLOOKUP if a value is in a database. If the value isn't in the database, the user can manually type it in but it overwrites the equation. I want to be able to "reset" the table to the original conditions. Ie, if a user overwrites my "=IF(ISBLANK($H4), "", VLOOKUP($H4,DCID[#All], 3, FALSE))" but later wants that equation back, I want to be able to write =IF(ISBLANK($H4), "", VLOOKUP($H4,DCID[#All], 3, FALSE)) to the cell and have it work.

Thoughts?

VBA to delete rows where first 4 words of text in column A are duplicated

$
0
0
I would like a macro to delete rows where the first 4 words of text in column A are duplicated.

So:

Cell A1: I have a dream today.
Cell A2: I have a meeting today.
Cell A3: I have a dream today.
Cell A4: I have a dream today. And I will wake up tomorrow.

would become:

Cell A1: I have a dream today.
Cell A2: I have a meeting today.

Many thanks.

Selecting cell that contains text and merging without data loss.

$
0
0
I am trying to come up with a code that will search through a column (H).
This column contains mostly numbers, but due to the method in which i must import this data some times it gets screwy and puts in a line of text.

So when searching through Column H I want to find cells that contain text instead of numbers and merge these to the cell to the left (same row, column G) without losing the data, and then delete the cell in column H and shift the rest of the row left.

This will help me get all of my cells lined up properly.


So I have the code for merging the cells, I am mostly having trouble with getting it to select the cell with Text instead of numbers and the cell to the left of that cell so it can merge them... Here is the code I have for merging.


Dim outputText As String
Const delim = " "

On Error Resume Next

For Each cell In Selection
outputText = outputText & cell.Value & delim
Next cell
With Selection
.Clear
.Cells(1).Value = outputText

End With



Any help would be great!

Excel Worksheet Export from Access Not Formatting Correctly

$
0
0
Hello

I have a database in Access and I have tried multiple methods to get the data from Access to Excel including using the import from access wizard. I've also tried exporting to Excel and then copying and pasting that worksheet into the workbook I'm working on. In all instances, even though the field that looks like a number in Access but is formatted as text in Access, is imported as a number.

The data from Access, where one line of data is a single abstract, is imported into Excel as one worksheet (raw data) and then a macro runs to place the data elements of each abstract into a certain cell per worksheet....so 10 abstracts, 10 worksheets representing each abstract.

Even if I format the column on the raw data worksheet as text, it still copies into the new worksheet as a number. The raw data worksheet has many columns that stretch to column KF. I could create an import wizard macro to define what format each column should be but if the source data changes that might be a pain to update. Because many columns in a row are text, it would probably be easier to create a macro to change all the formats on the raw data worksheet but I'm not sure where to start with that.

Can anyone suggest what they think would work best and give me some direction on where to start? Thanks so much.

Macro to create sum formula across all sheets except one activated in

$
0
0
Hello all

Let me give some background. I have a summary tab that will be in about 200 workbooks. The summary sheet is independent in each workbook but all tabs are exactly the same throughout all sheets and all workbooks..

I am looking for a macro that will create a formula that sums across all the tabs in a single workbook. Each summary page has 6000 cells that need to be summed and the remaining cells need to be untouched since there will be formulas sitting in the summary tab that is based of the summed numbers.

e.g. for one workbook that has 3 tabs SRC RCS and CRS and Summary, I want a macro that will put =sum('SRS'C!20!+'RCS'C!20!+'CRS'C!20!) in C20 of the summary tab. I want the macro to work as a range so that it will create this sum formula for C20:Q20 and create the formula for the corresponding cell in the rest of the sheets.

Is this possible? I've been racking my head and can't think of anything.

Adding a macro to replace data

$
0
0
Hello

I am trying to create an excel sheet to calculate each football players goal/game ratio.

The problem I am having is with the appearances column.

For example when I paste the data in from a website they can sometimes appear as 12(3) for example due to substitute appearances.

I would like to run a macro to get multiply the bracket by 30%. So far I have created a macro to replace to opening bracket to +(0.3* So the whole cell looks like this

12+(0.3*3)

I am struggling with the next step with how to alter my macro make it '=12+(0.3*3)' so then it will read 12.9

There is probably I simple answer but I'm pretty new to excel. So any help would be much appreciated

Thanks

macro to run in diffferent workbooks

$
0
0
I have recorded a macro creating a pivot and doing the necessary pivot filters. I would like to be able to run this macro in different workbooks since I will be doing this a several excel files daily.

As you can see in the code below the macro will only work on a specific worksheet.

Thanks

Sub accountlistingpivot()
'
' accountlistingpivot Macro
'

'
Windows("2015 09 17 - FE BPs and PTPs.xls").Activate
Range("A1:Y11812").Select
Sheets.Add
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"F03_F04_F05!R1C1:R11812C25", Version:=xlPivotTableVersion10). _
CreatePivotTable TableDestination:="Sheet1!R3C1", TableName:="PivotTable12" _
, DefaultVersion:=xlPivotTableVersion10
Sheets("Sheet1").Select
Cells(3, 1).Select
With ActiveSheet.PivotTables("PivotTable12").PivotFields("State_Code")
.Orientation = xlColumnField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable12").PivotFields("Cycle")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable12").AddDataField ActiveSheet.PivotTables( _
"PivotTable12").PivotFields("AccountNumber"), "Count of AccountNumber", xlCount
ActiveSheet.PivotTables("PivotTable12").AddDataField ActiveSheet.PivotTables( _
"PivotTable12").PivotFields("Billed_OB"), "Sum of Billed_OB", xlSum
With ActiveSheet.PivotTables("PivotTable12").DataPivotField
.Orientation = xlColumnField
.Position = 2
End With
With ActiveSheet.PivotTables("PivotTable12").PivotFields("Sum of Billed_OB")
.NumberFormat = "#,##0"
End With
Sheets("Sheet1").Select
Sheets("Sheet1").Name = "Summary"
End Sub

Listbox

$
0
0
Hello

how can i have a 2 column listbox, what will happen is that i will have an ID in textbox1 which is the ID number and when i click a search button its output in the listbox, will be:in the first column is the 1stname and the in the secondcolumn is the Surname

thank you

Toggle Shading Alternate Rows On/Off

$
0
0
Hi - I have 2 macros (below) that
1. shades every other row in named range "CF_Range" with conditional formatting "=MOD(ROW(),2)=0"
and inserts with top and bottom borders.
2. the other short macro turns this shading (banding), and top & bottom borders, OFF.

Q1 - can the macro be reduced at all? It was recorded so may contain some superfilous lines.
Q2 - how do I incorporate these into the 1 macro so it toggles shading (banding) between ON and OFF?

Tks

Code:

Sub Striping_On()  '======== Turn CF Striping ON  ===========
  ActiveSheet.Unprotect
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
    Application.EnableEvents = False

    Range("CF_Range").Select
    Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
        "=MOD(ROW(),2)=0"
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Borders(xlTop)
        .LineStyle = xlContinuous
        .ThemeColor = 1
        .TintAndShade = -0.14996795556505
        .Weight = xlThin
    End With

    With Selection.FormatConditions(1).Borders(xlBottom)
        .LineStyle = xlContinuous
        .ThemeColor = 1
        .TintAndShade = -0.14996795556505
        .Weight = xlThin
    End With

    With Selection.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorDark1
        .TintAndShade = -4.99893185216834E-02
    End With

    Selection.FormatConditions(1).StopIfTrue = False
   
  Application.ScreenUpdating = True
  Application.Calculation = xlCalculationAutomatic
 
  Range("A1").Select
  ActiveSheet.Protect
 
End Sub

Sub Striping_Off()  '========= Turns Striping OFF  ============
'
ActiveSheet.Unprotect
    Cells.FormatConditions.Delete 
    Range("A1").Select
    ActiveSheet.Protect
End Sub

Relay cell contents from another sheet within the same workbook when selecting a cell

$
0
0
Hello,

Due to the character limit of 'Input Message' under data validation, I would like to alternatively use a dedicated A1 cell in my main sheet to relay summaries from a summary reference sheet in the same workbook when I select a ' Main topic' cell in the main sheet. Essentially having that A1 cell as a dedicated message window. I'm a newb so please let me know if I haven't explained it clearly, thanks.

Michael

More levels of nesting than allowed

$
0
0
I have too many levels of nesting. I am sure there is a better way to do this any help would be appreciated.

=IF(N3="URS",IF(L3<6,"100",IF(L3<12,"80",IF(J3=1,IF((L3-15)<6,"100",IF((L3-15)<12,"80",IF(J3=2,IF((L3-30)<12,"80",IF((L3-30)<24,"50",IF(J3=3,IF((L3-45)<24,"50","FAIL")))))))))))

Basically if URS jobs are completed in less than 6 hours they get "100" less than 12 "80" less than 24 "50" more than 24 "0" however it is accross working days (8am - 5pm)

Break down:

If it is a URS job
If it is completed in less than 6 hours get 100
If it is completed in less than 12 hours get 80
If it is 1 calander day
If (total hours - 15) is less than 6 get 100
If (total hours - 15) is less than 12 get 80
If it is 2 calander days
If (total hours - 30) is less than 12 get 80
If (total hours - 30) is less than 24 get 50
If it is 3 calander days
If (total hours - 45) is less than 24 get 50
must be more than 24 hours get FAIL

Automatic calculation of maximum and minimum in a cell based on a specific value range

$
0
0
Hi there

I am looking for a macro (or what ever) to calculate automatically the maximum (or minimum) value in a cell depended on values of other cells. I'm explaining:
I have 4 cells that I insert values (for example from 5 to 15). The cells are A1, A2, A3 and A4
In another cell, C1, I have a function that depends on the values of that 4 cells mentioned before.
I need a macro where I can put manually the minimum and the maximum values (range) of cells A1 to A4 and will calculate the combination of values (integers) on that cells so that I can have the maximum (or minimum) value that cell C1 can get.

Note: This macro will be used in a lot of (and different) "4 cells" repeatedly.

Thanks in advance and I hope that macro is not so difficult for you! :-)

VBA to prevent saving

$
0
0
Hi,

I have the following code, which works fine to prevent people saving my file when I'm using excel 2007 (at work), however when I use it on my home computer, on excel 2013, the message pops up but I can still save the file, can anyone tell me why and how to fix it:

"Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
MsgBox ("The 'Save As' function has been disabled")
Cancel = True

End Sub"

Thanks

Tom

Excel VBA code for searching multiple rows of data.

$
0
0
Hi
I am new to VBA and learning to code. I am stuck doing this simple search.
ITEM Quantity PRICE
1 1 10
1 1 5
1 1 8
165876 1 1
165890 1 10
165890 1 2
166008 1 1
166731 1 3
166832 1 9.5
166833 1 9.5
166877 1 10.5
166898 1 4.5
167041 1 3.5
167056 1 2.5
167060 1 2.5
167180 1 1
167188 1 1
167477 1 2.5
167701 1 2

I want to search the first column for a specific number (sheet 1 is called item price) and then display the column data for all the matching numbers that exist in sheet 2. Here is my code, it stops after finding one record, I tried using ActiveCell.offset(1,0).select but it didnt seem to work:

Sub searchdata()

Dim lastrow As Long
Dim count As Integer

lastrow = Sheets("item_price").Cells(Rows.count, 1).End(xlUp).Row

For x = 2 To lastrow

If Sheets("item_price").Cells(x, 1) = Sheet2.Range("B3") Then
Sheet2.Range("A11, A12, A13, A14") = Sheets("item_price").Cells(x, 1)
Sheet2.Range("B11, B12, B13, B14") = Sheets("item_price").Cells(x, 2)
Sheet2.Range("C11, C12, C13, C14") = Sheets("item_price").Cells(x, 3)




End If

Next x

End Sub

Entire Workbook to PDF and more

$
0
0
Hello everyone,

1. I need a code that will convert an ENTIRE workbook into one PDF file

2. I would like it to save to the same location as excel file

3. I would like it to use the value of "J52" located on the "Information" worksheet as the name of the file

4. I would like to activate the macro using any keyboard shortcut...... possibly ctrl + shift + d

Is this possible?




5. I also use the code listed below to convert an individual worksheet into a pdf. I don't remember where I found it. It works ok now. However, when I use it, the save-as window with the correct file name displays and wants to save it to my documents unless you change it. I would like it do the same thing but the default location be the same as the original excel file. Can someone clean this up and make that work?

Thanks!

Code:


Sub PDFActiveSheet()
Dim ws As Worksheet
Dim strPath As String
Dim myFile As Variant
Dim strFile As String
On Error GoTo errHandler

Set ws = ActiveSheet

'enter name and select folder for file
' start in current workbook folder
strFile = ActiveSheet.Range("N75").Text & ".pdf"

myFile = Application.GetSaveAsFilename _
    (InitialFileName:=strFile, _
        FileFilter:="PDF Files (*.pdf), *.pdf", _
        Title:="Select Folder and FileName to save")

If myFile <> "False" Then
    ws.ExportAsFixedFormat _
        Type:=xlTypePDF, _
        Filename:=myFile, _
        Quality:=xlQualityStandard, _
        IncludeDocProperties:=True, _
        IgnorePrintAreas:=False, _
        OpenAfterPublish:=False

    MsgBox "A PDF version of this worksheet has been saved to your computer."
End If

exitHandler:
    Exit Sub
errHandler:
    MsgBox "Could not create PDF file"
    Resume exitHandler


Filter Data Then Plot It

$
0
0
Hi all.

I would love to improve how I make plots of my data. I have a spreadsheet (attached) wherein I enter data ("Data" worksheet). The last several columns of which, beginning with "CT to Rx Signing", I want to plot in several ways. You can see an example of some of the plots I want to make in the "Days From CT to Rx Signing" worksheet. This worksheet shows the output I want to make for the mentioned column in the "Data" worksheet, but the same is to be done for all the remaining columns to its right.

At the moment I have to manually filter the data in the "Data" tab and then copy and paste it into the appropriate location which I then, with the help of Excel formulas, I create histograms from and then plot (see colored cells in the "Days From CT to Rx Signing" worksheet).

I would like to be able to more fully automate the process such that I only have to enter new data into the "Data" worksheet and the remaining worksheets will automatically (or with the press of a button) update. Please advise.



Screenshot of "Data" worksheet:
http://i.imgur.com/dorhLiT.png


Screenshot of "Days from CT to Rx Signing" worksheet:
http://i.imgur.com/6f5DkJ4.png


The spreadsheet:
Planning Spreadsheet Test.xlsx

Macro to import Outlook Fields to Excel

$
0
0
Hi

I am trying to create a macro that collects the fields from each Outlook message in the selected Outlook folder and writes the values of the fields to an Excel worksheet.

The goal is from excel to be able to retrieved statical information in outlook by creating a link or a VBA.

EG. from - to - receive date - categories (if possible)


Thank you for sharing your knowledge.



Nick

[SOLVED] Save worksheet as new workbook

$
0
0
Hi all,

I want to make a macro that allows me to easily save worksheets as new workbooks in the same path as the original workbook.

This is what I got so far:

Code:

Sub SaveWorksheet()
  Dim wb As Workbook
  Dim Start As String
  Dim Finish As String
  Dim Name As String
 
  Start = Sheets("Example").Range("F5")
  Finish = Sheets("Example").Range("M5")
 
  Sheets("Example").Copy
  Set wb = ActiveWorkbook
  Name = "Text" & " " & Start & "" & " - " & "" & Finish
  With wb
    .SaveAs ThisWorkbook.Path & "\Name.xlsx"
    wb.Close
  End With
End Sub

In this code 'Start' and 'Finish' are dates in cells.

The only problem is that the worksheet isn't saved with the name I gave it behind 'Name' but actualy with the name Name.xlsx..

Is there any easy way that can fix my problem?

Hope you have some tips :)

- Daan

Getting run-time error object doesn't support this property or method

$
0
0
Hi friends,

I want to convert a file to PDF and then take a print out.
I’m using ‘dopdf-7 ‘to convert a workbook to PDF.
I have recorded a macro for it which is working fine but I didn’t get any code to convert a workbook to PDF using ‘dopdf-7 ‘.
I’m getting run-time error 438 ‘Object doesn’t support this property or method’ on the line:

Code:

.Preview = True
The code is:
Code:

Option Explicit

Sub PrintPage()

With Application
.ScreenUpdating = False
.EnableEvents = False
.Calculation = xlCalculationManual
End With

    With ActiveSheet.PageSetUp
        .LeftMargin = Application.InchesToPoints(0.590551181102362)
        .RightMargin = Application.InchesToPoints(0.393700787401575)
        .TopMargin = Application.InchesToPoints(0.393700787401575)
        .BottomMargin = Application.InchesToPoints(0.393700787401575)
.PrintQuality = 300
        .Orientation = xlPortrait
        .PaperSize = xlPaperLegal
        .BlackAndWhite = True
        .Zoom = 68
        .PrintTitleRows = "$1:$4"
        .Preview = True
    End With
    ActiveWindow.SelectedSheets.PrintOut Copies:=1
   
    MsgBox "Done!", 64
   
With Application
.Calculation = xlCalculationAutomatic
.EnableEvents = True
.ScreenUpdating = True
End With

End Sub

Any help will be highly appreciated.

Thanking you in anticipation.

how to loop through listboxes on a sheet

$
0
0
Hi all,

I am facing an issue to loop through 3 listboxes on a worksheet. I tried to use following code to loop, but no success.
Code:

Dim lbx(3) As Object
For i = 1 To 3
    Set lbx(i) = ActiveSheet.ListBox(i)
        lbx(i).ListFillRange = ""
        lbx(i).ListFillRange = ActiveWorkbook.Names.Item("DB_1").RefersToRange.Address

I also tried to dim lbx(3) as Listbox, but still no success.
error438 occurs when run in "Set lbx(i) = ActiveSheet.ListBox(i)"
Viewing all 49921 articles
Browse latest View live