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

Macro to Print Sheet on 2 pages

$
0
0
I have 18 sheets to print which are all of the same range

I have attached a sample workbook containing one sheet where I written a macro to print the data


I would like the macro to print this so that it fits on two pages


Your assistance is most appreciated

Code:

sub PrintData()


Dim LastRow As Long
Application.ScreenUpdating = False
Sheets("Sales1").Select
    LastRow = Sheets("sales1").Cells(Rows.Count, "A").End(xlUp).Row
With ActiveSheet.PageSetup
.PrintArea = "A2:Q" & LastRow
.PrintGridlines = True
.PrintTitleRows = ""
.PrintTitleColumns = ""
.LeftHeader = "&D&T"
.CenterHeader = "Sales1"
.Orientation = xlLandscape
End With
Application.ScreenUpdating = True
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
      End Sub


[SOLVED] Find Replace items in list to targeted range Range=A:A, What=Col_x Replacement=Col_y

$
0
0
Hi Guys

Please see attached and example of what I'm trying to achieve

Is it possible to replace the values, in a specified range (column ref or heading no preference)
with the list contents of one column, replaced with the corresponding values of another column, row by row

ie look in column A
and check for presence of F1 and replace it with the value in G1,
then check for F2 and replace with G2,
then F3 to G3
...etc

The hurdle is this "looping" for me, although I recognise I could declare each and every row cell
Many thanks for all your help

Export excel sheet data in to text file by iterating data with other sheet

$
0
0
Hi,

i am new to development, i have googled my requirement but i did not get what i am looking for.Below is my requirement..

i have to sheets(sheet1 and sheet2) in excel file.
Sheet1 has data of server name, starttime and endtime
sheet2 has user and his name.
i want to provide access to each user to the servers mentioned sheet1 in below format. and export that to text file

server1:user1:hisname:starttime:endtime
server2:user1:hisname:starttime:endtime...


Any guidance or help much appreciated
Attached Files

[SOLVED] Number in Specific cell after criteria in 2 other specific cells.

$
0
0
Hi. I have been playing to make a macro for below criteria, but so far no luck.-

I need a specific number displayed in Cell E24 Sheet2
After a criteria in E7 and E20 both also Sheet2.
Below you can see the criteria and also i attached a test sheet, which would be good to have a look at.
I need a macro for this, so if some have time would be great to have it solved.
Thanks in advance
Abjac

Below Criteria.

Text in Sheet2 Cell E7 is Standard

Number in Sheet2 cell E20 is minus 80 Display in Sheet2 cell E24 0
Number in Sheet2 cell E20 is bigger or equal 80 and smaller than 90 Display in Sheet2 cell E24 50
Number in Sheet2 cell E20 is bigger or equal 90 and smaller than 100 Display in Sheet2 cell E24 70
Number in Sheet2 cell E20 is bigger or equal 100 and smaller than 110 Display in Sheet2 cell E24 100
Number in Sheet2 cell E20 is bigger or equal 110 and smaller than 120 Display in Sheet2 cell E24 120
Number in Sheet2 cell E20 is bigger or equal 120 Display in Sheet2 cell E24 120

Text in Sheet2 Cell E7 is Performance

Number in Sheet2 cell E20 is minus 80 Display in Sheet2 cell E24 0
Number in Sheet2 cell E20 is bigger or equal 80 and smaller than 90 Display in Sheet2 cell E24 50
Number in Sheet2 cell E20 is bigger or equal 90 and smaller than 100 Display in Sheet2 cell E24 70
Number in Sheet2 cell E20 is bigger or equal 100 and smaller than 110 Display in Sheet2 cell E24 100
Number in Sheet2 cell E20 is bigger or equal 110 and smaller than 120 Display in Sheet2 cell E24 120
Number in Sheet2 cell E20 is bigger or equal 120 and smaller than 150 Display in Sheet2 cell E24 150
Number in Sheet2 cell E20 is bigger or equal 150 and smaller than 200 Display in Sheet2 cell E24 200
Number in Sheet2 cell E20 is bigger or equal 200 Display in Sheet2 cell E24 300
Attached Files

Move Time Amendments

$
0
0
Hi Guys!

I'm trying to create a macro to change original start times of races from a seperate time change column. I want this to run as a macro rather than as when entered because the amendments may be copied from a different sheet. I have attached a sheet to show you this process. Thanks for any assistance you can provide.

Thanks
Attached Files

This macro works in Excel 2010, but not Excel 2016.

$
0
0
Hi,

The macro below is intended to make a clickable hyperlink to all open files in the source spreadsheet. It works fine in Excel 2010 but not at all in Excel 2016 - I think because 2016 uses separate instances of Excel. Can someone assist with a re-write to make it work in Excel 2016? Thanks so much in advance.

--------------------------------
Sub Button3_Click()
Dim wb As Workbook
Dim i As Long

With Sheet1.Range("A:A")
.ClearContents
i = 0
For Each wb In Application.Workbooks
If wb.Windows(1).Visible Then
i = i + 1
Cells(i, 1).FormulaR1C1 = "=hyperlink(" & Chr(34) & wb.Path & "\" & wb.Name & Chr(34) & ")"
End If
Next wb
End With
End Sub

Userform textboxes, select first textbox

$
0
0
Hi. With the code below, a userform with textboxes shows. Textboxes show contents of cells.
I want to select the first textbox automatically, as per image below.
Trying to use ".SetFocus" but will not work.

Snapshot.png

FORM CODE
Code:

Option Explicit

'General
Private WithEvents MyApplication As Excel.Application
Public WithEvents cDelegate As ClassDelegate
'Ranges
Dim RangeColumn As Range
Dim Cell As Range
'Textboxes
Private TextBoxes As Collection
Private mActiveTextBox As MSForms.TextBox
Dim TextBox As MSForms.TextBox

'INITIALIZE
Private Sub UserForm_Initialize()
    Set cDelegate = New ClassDelegate
    Call FormCreation(True)
End Sub

'ACTIVATE
Private Sub UserForm_Activate()
    ButtonExit.SetFocus
End Sub

'CREATE FORM
Private Sub FormCreation(BuildButtons As Boolean)
    Dim cEvents As ClassEventsBoxes
    Dim Box As MSForms.TextBox
    Dim BoxTop As Long, BoxHeight As Long, BoxLeft As Long, BoxWidth As Long, BoxGap As Long
    Dim BoxName As String
    Dim Index As Long
    'Miscellaneous
    Set MyApplication = Application
    BoxHeight = 40: BoxTop = 0: BoxLeft = 0: BoxWidth = TextBoxFrame.Width: BoxGap = 0
    Index = 1
    If TextBoxes Is Nothing Then
        Set TextBoxes = New Collection
    End If
    'Create textboxes
    For Each Cell In Selection
        If Index > TextBoxes.Count Then
            Set cEvents = New ClassEventsBoxes
            Set cEvents.cDelegate = cDelegate
            BoxName = "TextBox" & Index
            Set Box = Me.TextBoxFrame.Controls.Add("Forms.Textbox.1", BoxName, True)
            Set cEvents.TextBoxGo = Box
            TextBoxes.Add cEvents
        Else
            Set Box = TextBoxes(Index).TextBoxGo
        End If
        With Box
            .Height = BoxHeight: .Top = BoxTop: .Left = BoxLeft: .Width = BoxWidth
            .AutoWordSelect = False
            .Font = "Courier New"
            .Font.Size = 20
            .Text = Cell.Formula
        End With
        Index = Index + 1
        BoxTop = BoxTop + BoxHeight + BoxGap
    Next Cell
    'Remove extra textboxes
    Do While TextBoxes.Count > Index
        TextBoxes.Remove TextBoxes.Count
    Loop
    'Activate first textbox
    Me.TextBoxFrame.TextBox1.SetFocus
End Sub

'TEXT BOX EVENT
Private Sub cDelegate_TextBoxGoChanged(TextBoxGo As MSForms.TextBox)
    Set mActiveTextBox = TextBoxGo
End Sub

'EXIT
Private Sub ButtonExit_Click()
    Unload Me
End Sub

'TERMINATE
Private Sub UserForm_Terminate()
    Dim Index As Long
    For Index = TextBoxes.Count To 1 Step -1
        Me.TextBoxFrame.Controls.Remove TextBoxes(Index).TextBoxGo.Name
        TextBoxes.Remove Index
    Next
    Set TextBoxes = Nothing
    Set MyApplication = Nothing
End Sub

Attached Files

[SOLVED] Macro to extract data where there are 2 leading asterisks

$
0
0
I have data on sheet "raw data". Where the text in Col "A" has 2 leading asterisks, then I want to copy this data in Col A from row 6 onwards up to Col C to sheet "Extracted data" from row 2 onwards


I have manually copied the data to show you what I am trying to achieve



I am looking for a macro to copy and paste the data as per my requirement above


Your assistance regarding the above is most appreciated

Macro or query formula to add different sheets data in one

$
0
0
Hi All

Lovely people!

Will highly appreciate help on this, This query is related to the flow statement data to summarise in one sheet

The three sheets data I am looking to add and in one sheet Year 2020

asking help to create macro or query for best visuals

basically summary of 3 different sheet data into Year 2020 sheet


I hope I explained it proper, let me know please if any question

Find attached workbook.

Thanks a lot in advance for help


Kind Regards
Attached Files

Date stamp on Cell Information Change

$
0
0
Good Afternoon,

Relatively new to using VBA in excel so go easy one me lol.

Current setup is I have one worksheet with a macro filling checkboxes as required and linking the cell to another sheet for the true false values.

It is on this sheet I want the TRUE / FALSE (or blank as the case may be until the check boxes are originally ticked) to trigger a time stamp for each cell with a textbox in certain coluns.

I currently have code that works in that if I manually type something into the cells being monitored for time stamp it puts a time stamp in the relevant cell. However if I use the checkbox on the other sheet I don't get a timestamp when the cell changes?

Code:

Private Sub Worksheet_Change(ByVal Target As Range)
  Const ColumnsToMonitor As String = "G:Z"
  Const DateColumn As String = "F"
  Application.EnableEvents = False
  If Not Intersect(Target, Columns(ColumnsToMonitor)) Is Nothing Then
    Intersect(Target.EntireRow, Target.Offset(0, 20)).Value = Format(Now, "dd mmm hh:mm")
  End If
  Application.EnableEvents = True
  Columns("AA:AZ").EntireColumn.AutoFit
End Sub

Is my current code for the time stamping, really don't want to get into calling to the check boxes on sheet one and refering back to sheet2 as I developed enough of a headache getting that far.

Any help or advice much appreciated.

Help in (If Statment) VBA

$
0
0
Greetings,

Basically, I'm trying to run this code into userform & it should be displayed on listbox after pressing Add btn

but I want to make if statement if END TIME is blank then it should procced because now it giving Error msg (Type Mismatch)

furthermore, if end time less than START TIME then it shows Error msg


Thanks!



Code:


Private Sub cmdAdd_Click()

Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("outputs")

Dim last_Row As Long
last_Row = Application.WorksheetFunction.CountA(sh.Range("A:A"))


    sh.Range("G" & last_Row + 1).Value = TextBox4.Value & " " & ComboBox4.Value                                                ' Start date & time (mm/dd/yyyy hh:mm)
    sh.Range("H" & last_Row + 1).Value = TextBox5.Value & " " & ComboBox5.Value                                                ' End date & time (mm/dd/yyyy hh:mm)       
   
    sh.Range("I" & last_Row + 1).Value = sh.Range("H" & last_Row + 1).Value - sh.Range("G" & last_Row + 1).Value        'End - Strat

Last Date of the month Highlight using macro

$
0
0
Hi,
I have a series of dates with corresponding dates. I want to mark the last date of the month in red color for each month.
I started with EOmonth and text formula to determine the month.
But i want to mark the last date in color using a macro, so that i can use it for any sample.
I am attaching the file with dates and formula deleting the data.
Attached Files

Key word alert from sentences plus addendum

$
0
0
On sheet 1 column D, I have a list of short sentences that describe the trip a horse had. If there is a key word in that sentence that shows the horse had trouble, I would like to put a “C” in column E to denote that as shown on Sheet 2. But I don’t want it on sheet 2, I want it in the same sheet (sheet1). Sheet 2 is for demonstration purposes only.

There are certain key words that would be significant to denote the trouble such as the word “steadied” or “jostled” etc. Those words are also sometimes abbreviated. So I would like the macro to refer to a mini list of words that can be added to that would trigger the “C” notation. Thanks.
Attached Files

[SOLVED] If statements and Select statements in active controls userform

$
0
0
I am needing to add a numerical method to the same equation of state that I am using via option button. I am unsure how to write the if statements because there are multiple if statements that I am needing to write for my unit conversions etc. I have the file 1 attached which is before and added the 2nd numerical method which is the secant method. I keep getting an "end if" without if statement and also an error on "end select" without select. I am not understanding how to write these multiple statements inside of each or if there is a better way to do so. Thanks the help is much appreciated!
Attached Files

Merge multiple csv files with the same file name into one csv

$
0
0
Dear Expert,

Let's say i have the below files in two folders:

Folder 1:
ex1.csv
ex2.csv
ex3.csv
ex4.csv
ex5.csv
ex6.csv
....

Folder 2:
ex1.csv
ex2.csv
ex3.csv
ex4.csv
ex5.csv
ex6.csv
....

Folder 3:
The final sheet should be saved here

Can someone tell me how I can merge ex1.csv from "folder 1" with ex1.csv from "folder 2" and save it under the name ex1.csv in "folder 3"?4
Also can I remove the first row of ex1.csv in folder 2 so I don't have two headers?

I have 3000 files that are duplicated twice.

Thank you

userform not responding infinte loop

$
0
0
I am having to make calculations for two different numerical methods being newton rapson and secant. I have a program written with just newton Rapson and it runs fine no problems. However, in my second program "programn2" once I integrate the newton Rapson method into it, I keep getting the equation not converging and causing an infinite loop. program 2 still works for secant method however. Any help is greatly appreciate thanks.
Attached Files

auto update pivot table

$
0
0
ive attached a demo pivot table here and want it to update,*

if it helps to put the pivot table on another page I will do that.

I want to be able to add new dates, invoices and $ amounts to the dataset and have it update in the pivot table..I thought this would be the case but it is not.

kindly,
Attached Files

Macro to supress Outlook Message

$
0
0
I have the following code to email several sheets where there is an email address in cell A1

When running the macro, I get an outlook pop and I have to setlect allow after each sheet is emailed, which is time consuming


I want all the sheets to be emailed, without having to click on allow each time a sheet is being emailed

It would be appreciated if someone could amend my code to email all the sheets at once or suppress the pop up outlook message




Code:

Sub mailWorksheets()                               
Application.DisplayAlerts = False
Application.ScreenUpdating = False             

For Each w In ThisWorkbook.Worksheets     
If w.[a1].Value Like "*@*" Then                  'check for email address in cell [A1]
w.Copy                                                     

ActiveWorkbook.SaveAs "Sheet " & w.Name & " of " & ThisWorkbook.Name & ".xls"
zSendTo = ActiveSheet.[a1].Value                'email recipient
zSubject = "Sales Data"                 
ActiveWorkbook.SendMail zSendTo, zSubject  'send email to recipient

ActiveWorkbook.ChangeFileAccess xlReadOnly  'change workbook to read-only for deletion
Kill ActiveWorkbook.FullName                        'delete saved copy of temporary workbook
ActiveWorkbook.Close False                            'close temporary workwook

End If                                                         
Next w                                                       


Application.ScreenUpdating = True         
Application.DisplayAlerts = True
End Sub

Attached Images

7 column array unique list of alphabetized names ignoring blanks with highlighting

$
0
0
I would like some help with using a 7 column array A2 through G25. Show a unique list of alphabetized names, ignoring blanks, in column J starting on row 1 and when you click on one of the names in Column J all matches are highlighted in the array. I'm just guessing that something like this would have to be a vba script???
Thanks in Advanced

[SOLVED] Sum total by partial text

$
0
0
Hello everyone

I have a column of raw data with some items (Column B) and I already have other items in Column K which I need to search partially for them in Column B and sum the total for the suitable item
The attachment will be better for clarification. The desired output in Column L
Thanks advanced for help

Posted here: https://www.eileenslounge.com/viewto...p?f=30&t=34367
Attached Files
Viewing all 50018 articles
Browse latest View live