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

auto save workbook

$
0
0
Hi All,

I had the following code written for me but I want to be able to save the workbook everytime an entry is made.

Public Sub addEnquiry()

Dim MediumType As String
Dim EnquiryReason As String

Const Medium As Long = 1
Const Reason As Long = 2

With Sheets("input")
If .ListBoxes(Medium).Value = 0 Or .ListBoxes(Reason).Value = 0 Then
MsgBox "Complete both boxes"
Exit Sub
End If

MediumType = .ListBoxes(Medium).List(.ListBoxes(Medium).Value)
EnquiryReason = .ListBoxes(Reason).List(.ListBoxes(Reason).Value)
.ListBoxes(1).Value = 0
.ListBoxes(2).Value = 0
End With

With Sheets("data").Range("a1").CurrentRegion
.Offset(.Rows.Count).Resize(1, 3).Value = Array(MediumType, EnquiryReason, Now())
End With


End Sub

Can anyone help?

Thanks :)

Macro to protect data Validation rules

$
0
0
Hi,

can anyone help me to create macro in order to protect Data Validation rules.

e.g. If user copy and paste cells from others source which is not in the same validation criteria or not contain any validation rules, the existing validation will gone.

so, is there any macro which will be able to automatically run to prevent the data validation?

Regards,
Farid.

[SOLVED] Need macro to run on mulitple sheets

$
0
0
Have working macro that does what I need (hiding columns based on criteria):
Code:

Sub Day21Window()
'
' Day21Window Macro
' Create View Window After Date Set
'


Application.ScreenUpdating = False

For Each Col In Range("H1:IG1").Columns
    If Col.Columns.Cells(68, 1) = "H" Then
        Col.EntireColumn.Hidden = True
    Else
        Col.EntireColumn.Hidden = False
    End If
Next Col
         
            Application.ScreenUpdating = True

 
End Sub

It currently executes in Sheet A, but I need it to also execute in Sheets B, C, and D (potentially more) without copying and executing in each sheet individually. Do I "nest" this macro in another macro, or does it become it's own set of instructions?? Thank you.

Wanting to change the title in a VBA script

$
0
0
Hi all,

I am new to VBA. I can understand the concept of what I am looking at, but would like to be pointed in the right direction.

I have a daily report that has everything built into it, when I complete the report we have a Marco built in to save the file as a PDF and e-mail the file to the correct people.

My question is, I want to change the name of the PDF file from "Daily Volume Report" to EGP Daily Volume Report." Can anyone point me in the right direction? I can post the code as well.

Just let me know.

Thanks,
Jason

Updating 2 Pivot table filters based on a single cell URGENT please

$
0
0
Ok I have 2 Worksheets, 1 "Report" contains my end report, 2 "Data" contains two pivot tables named "Pivot" and "Pivot1". Cell "B3" on "Report" is the cell I want to type a Shop number into and filter both pivot tables by that column. The column is named "Shop" in both tables. Below is the code I have to update one table and it works, for one, here are my questions

1)How do I update the second pivot table at the same time?



2) This runs a little slow and also the pivot tables update immediately, but I have to click another cell after it runs to make the "Report" update.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Intersect(Target, Range("B3")) Is Nothing Then Exit Sub

Dim pt As PivotTable

Dim Field As PivotField

Dim NewCat As String

Set pt = Worksheets("Data").PivotTables("Pivot")

Set Field = pt.PivotFields("Shop")

NewCat = Worksheets("Report").Range("B3").Value

With pt

Field.ClearAllFilters

Field.CurrentPage = NewCat

pt.RefreshTable


End With

End Sub
:confused::confused::confused:

Microsoft Excel Stopped Working Error

$
0
0
I have a Macro button in my Excel Spreadsheet, everytime I close the spreadsheet it gives me this error "Microsoft Excel Stopped Working"
I have attached Spreadsheet to show example.

Please help.
Attached Files

Password Protect On Open VBA with Range (SaveCopyAs)

$
0
0
How would I re-write the following code to work with an "On open Password" prompt?

Code:

ActiveWorkbook.SaveCopyAs strFolder & Sheets("Control").Range("A2").Value & ".xlsm", Password:=Sheets("Control").Range("K2")

Compile error : Sub or Function not defined - even after solver has been referenced

$
0
0
Hi everyone,

I wrote some really straightforward code (see below) but when I try to run it, I get this error : Compile error : Sub or Function not defined. I've looked up on the Excel help and on the internet and I found out that this might be caused by the solver not being referenced. But, this is fixed now but I still get the same error message.

I'm using Excel 2007 - Windows.

Here is the code :

Sub Macro1()

Dim i As Integer
Dim j As Integer
j = 4
For i = 1 To 4000
If ActiveSheet.Cell(i, 12).Value = 1 Then
ActiveSheet.Cell(j, 15).Value = ActiveSheet.Cell(i, 2)
j = j + 1
Dim k As Integer
k = i + 1
While ActiveSheet.Cell(k, 12).Value = 0

k = k + 1
Wend
ActiveSheet.Cell(k, 16).Value = MaxValue(ActiveSheet.Range(Cells(i, 7), Cell(k - 1, 7)).Value)
End If

Next i
'
End Sub

Please let me know if you think this comes from an error in the code or most likely from the way I referenced the solver.
I'm happy to provide you with any further information.

Thank you very much for your help.

Best,
Etienne

Index match array

$
0
0
Hi im trying to do an index match to bring back a cell.
On Sheet 2 I have number agent Ids on row 1 ( i.e 15522) along with a load of dates in column A.
On the data dump sheet im trying to retrieve a time of when an agent ID logged in ( Agent Login in cell A1)

For example
On the 1st of May (cell a3) Agent 15522 logged in at 09:28:07 ( this is highlighted in yellow on row 760) i need that time to display on Sheet 2 B3.
I need this to work for all the days and agents across all each day.
What is the best formula to use?
Attached Files

Many to One Matching

$
0
0
Hello All,

I have been trying to come up with a way to compare data in two columns of a sheet in order to assist in matching them off. I've attached a sample file of my raw data and a results tab with generally what I am looking for. There could be multiple items in column J that would match off with a single item in column I.

One caveat - the items from column J that combine should share the same Sec # (column N) and Post Date (column D). Additionally there may be some items that simply do not have a match at this point.

I have tried all sorts of things including creating a Unique ID with the above mentioned columns N&D, doing a pivot table and then a SUMIF and a VLOOKUP back to column I to see if I can get any matches. I do get a few hits, but there really should be quite a few (my method found 17, and someone else found over 100 by looking manually through various grouping and sorting methods).

I'm hoping to come up with something that will automate the process a bit. Just let me know if anyone has any thoughts!







Zarley
Attached Files

How to incrase invoice number and save to desktop as PDF using cell data for filename

$
0
0
Our business has a spreadsheet set up for invoicing. A Macro has been created to increase the invoice number, save to the desktop as a PDF with a file name taken from the cells

This is working on my colleagues mac but when we've loaded onto my computer it errors, when I debug I am getting the following error:

Sub Macro3()
'
' Macro3 Macro
'

'
Range("g10").Select
[g10] = [g10] + 1

k = Range("k10").Value
l = Range("l10").Value
m = Range("m10").Value
n = Range("n10").Value
o = Range("o10").Value
'
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
k & " " & l & m & " " & n & m & " " & o, Quality:=xlQualityStandard, IncludeDocProperties _
:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True





End Sub

Does anyone have any idea how to solve this, I have no experience amending Macros

Thanks!

Copy different ranges from different sheets into one?

$
0
0
Hi,

I am a very unskilled VBA editor, and was hoping someone could help me with this macro.

I would like to copy different ranges from different sheets starting from one cell and then copying until the cell comes up empty. I would need the first range to copy to a specific cell into the master worksheet. The other ranges would need to copy underneath after the first range has completed copying I would need to do these for 6 sheets.

Bold Words In VB

$
0
0
Hi All,

I have VB code to send a mail from outlook. Here I need to bold few of the word bold. Is it possible to do so?

strings and arrays

$
0
0
when I use the first myArray below this macro outputs a message box that tells me all the values I put into the array, however when I try to read some strings into the array from range A14 to A21 (sheetnames to look for), the code errors at the line: msgString = msgString & myArray(z) & vbCrLf


Code:

Sub arry()

 Dim myArray As Variant
 Dim msgString As String
 Dim z As Long

 Worksheets("Controls").Activate

 myArray = Array(32, 39, 56, 57, 71, 90, 107, 134)
 'myArray = Range("A14:A21")

 
 For z = LBound(myArray) To UBound(myArray)

  msgString = msgString & myArray(z) & vbCrLf

 Next z

 MsgBox "the values of my array are: " & vbCrLf & msgString

End Sub

Delete Row Based on Field Value

$
0
0
Hi-
I'm diving back into VBA after a year out of the mix.

I need a code to delete all rows with a 0 in Column F below Row 4.

Thoughts? Thanks.

Also, the paid help, anyone have more details on this? How many points it takes?

--tj

Macro to delete row

$
0
0
I have date from column a to k

I have a formula on column L

I want macro to delete all rows with #N/A

loop thru cells in column and depending on cell value, populate another cell with a value

$
0
0
can someone help me with my macro? i need to loop thru cells in column A and depending on each cell's value, populate another column's cell with a value i need to hardcode in the macro using a case statement.

attached is a workbook containing a macro MODULE3.OPAY showing my attempt (which is poor, i know). the way it is now, the macro populates the whole column A with 16750, but i need to have it place column header 'COID' in Q2, then place the new values in column Q.

thanks so much in advance for your assistance!!

Pam White
pam.white@lpnt.net
Attached Files

How can I ensure a workable code among different computers?

$
0
0
Hi all,

I got a vba code which works well in my PC (windows XP) using Excel 2010. The same file cannot work in another PC (Win 7) also using Excel 2010.
Please see below code. Does anyone have any ideas? Thanks
Code:

Sub Grouping()

Dim MyFolder As String, MyFile As String, NewWB As String, RawWB As String, LastRow As Integer
Dim FileNameAndPath As Variant

RawWB = "SalesReportSample (2014.05.10) - by Product types"
NewWB = "SalesReportSample (" & Format(Date, "yyyy.mm.dd") & ")"
FileNameAndPath = Application.GetOpenFilename()
Workbooks.Open Filename:=FileNameAndPath
Workbooks.Add
MyFolder = GetDirectoryToSave
ActiveWorkbook.SaveAs Filename:=MyFolder & "\" & NewWB & ".xlsx"
Workbooks(RawWB).Worksheets(1).Range("a1:E1").Copy _ ' PROBLEM IS HERE, ERROR 9 Subscript out of range
Workbooks(NewWB).Worksheets(1).Range("a1")
LastRow = 1
   
For i = 1 To Workbooks(RawWB).Worksheets.Count
    Workbooks(RawWB).Worksheets(i).Range(Workbooks(RawWB).Worksheets(i).Cells(2, 1), Workbooks(RawWB).Worksheets(i).Cells(2, 5).End(xlDown)).Copy _
    Workbooks(NewWB).Worksheets(1).Range("A" & LastRow + 1)
    LastRow = Workbooks(NewWB).Worksheets(1).Range("A1").End(xlDown).Row
Next

End Sub

Copy and paste data to bottom empty row on new sheet

$
0
0
Hi,

I'm fine excel when it comes to formulas, but my knowledge of VBA barely scratches the surface. I'm hoping someone can help me figure out my problem.

I'd like cell L3 and M3 to copy and paste from a sheet titled "Local Regression" to column A and B in a sheet called "Historical increase". Is there a way to do this? In my mind I had imagined that I could do it by recording a macro and then insert a button so after an item was picked from a dropdown in L3 and a # typed in M3, that they could click the button and it sends it to the new sheet without writing over historical data.

If there is a VBA code for this, is there also a way to include it as a button? I've only pasted VBA into spreadsheets a couple of times before, so if you can dumb it down for a normal human I would appreciate it! :cool:

copying data from userform to another workbook without opening second workbook

$
0
0
I have created userform and it works fine.
Following code assigned to 'SUBMIT' button in userform - works fine.
I am trying to include code where certain data from userform is also copied to workbook2 ( of course without opening it)- as marked in red...below
Code:

Private Sub CommandButton1_Click()
Dim lastrow As Long

'Sheets("sheet1").Unprotect "abcd"
lastrow = Worksheets("sheet1").Range("A" & Rows.Count).End(xlUp).Row
With Worksheets("sheet1").Range("a1")
.Offset(lastrow, 0).Value = Me.DTPicker1.Value
  .Offset(lastrow, 1).Value = Me.ComboBox1.Value
 
  .Offset(lastrow, 2).Value = Me.TextBox2.Value
  .Offset(lastrow, 3).Value = Me.ComboBox2.Value
  .Offset(lastrow, 4).Value = Me.ComboBox3.Text
  .Offset(lastrow, 5).Value = Me.ComboBox4.Text
  .Offset(lastrow, 6).Value = Me.TextBox3.Value
  .Offset(lastrow, 7).Value = Me.DTPicker2.Value
  .Offset(lastrow, 8).Value = Me.DTPicker3.Value
 
  .Offset(lastrow, 9).Value = Me.DTPicker4.Value
  .Offset(lastrow, 10).Value = Me.ComboBox10.Value
  .Offset(lastrow, 12).Value = Me.ComboBox11.Value
  .Offset(lastrow, 13).Value = Me.DTPicker6.Value
  .Offset(lastrow, 17).Value = Me.DTPicker5.Value

'.Offset(lastrow, 0).Value....Workbooks("book2.xlsx").Sheets("sheet1").Range("A" _
            & Rows.Count).End(xlUp).Offset(1, 0)

( workbook2 is saved at C:\2031\)
 
  'clear the form
ComboBox1.Value = ""
TextBox2.Value = "Not Known"
ComboBox2.Value = ""
ComboBox3.Value = "Not yet Informed"
ComboBox4.Value = ""
TextBox3.Value = ""
DTPicker2.Value = ""
DTPicker3.Value = ""
DTPicker4.Value = ""
ComboBox10.Value = ""
ComboBox11.Value = ""
DTPicker6.Value = ""
DTPicker5.Value = ""
DTPicker1.Value = ""
 

 End With
End Sub

Any help is appreciated.
Many thanks:):)
Viewing all 49921 articles
Browse latest View live