728x90

셀의 셀서식을 내맘대로 변경하기

해야할일
1. 엑셀서식을 숫자로
2. 음수는 - 빨간색으로
3. -(하이픈) 인경우는 0으로
4.#NA 에러표시는 0으로
5. 4열부터 +50열까지만 변경(전체행하기엔 속도가 느려짐)
6.랜덤하게 셀을 선택해도 변경가능

완성
Sub a숫자형식변경a()
    Dim selectedRows As Range
    Dim row As Range
    Dim selectedRowNumbers As String
    
    ' Check if any rows are selected
    On Error Resume Next
    Set selectedRows = Selection.Rows
    On Error GoTo 0
    
    If selectedRows Is Nothing Then
        MsgBox "No rows selected."
        Exit Sub
    End If
        
    ' Loop through each selected row and build the string of row numbers
    For Each row In selectedRows
        iRow = row.row
        icol = 4
        Set rng = Range(Cells(iRow, icol), Cells(iRow, icol + 50))
        For Each cell In rng
            If IsError(cell.Value) Then  '#NA를 0으로
                If cell.Value = CVErr(xlErrNA) Then
                    cell.Value = 0
                End If
            ElseIf cell.Value = "-" Then '-하이픈을 0으로
                cell.Value = 0
            End If
        Next cell
        
        With rng
            .NumberFormat = "#,##0_);[Red](#,##0)" '형식지정
            .HorizontalAlignment = xlCenter
            .Value = .Value ' This line re-evaluates the cell values to apply the formatting
        End With

    Next row
End Sub

결과확인하기

변경전

(매크로실행시 랜덤하게 행 선택)

변경후

#NA 오타(테스트로 임의작성)..#N/A(실제 오류)면 정상동작 확인

 

728x90
728x90

일단 대충 매크로 기록으로 '개인용 매크로 통합문서' 하나 만듬

1.엑셀 리본 커스터마이즈

2.매크로

C:\Users\nigaw\AppData\Roaming\Microsoft\Excel\XLSTART
그럼 해당위치에 PERSONLA.XLSB 가 만들어짐

해당 파일에서 매크로 만들면 됨

*PERSONLA.XLSB 위치확인
① 보기 - ② 직접 실행 창 (단축키 Ctrl + G) 를 클릭합니다.
기본적으로 ③ 직접 실행 창 이 표시되어 있는 경우도 있으니 그럴 경우엔 바로 아래 이미지로 내려가시면 됩니다.
Print Application.StartupPath

 3. 엑셀 매크로 안먹힐때
다시 깔고
레지스트리 편집기에서 excel삭제하면 엑셀설정 초기화.
연결편집에 알수없은 상관없음. 낚이지말자

 

728x90
728x90

추가기능으로 특정문자가 포함된 행 을 삭제하기

#2.g16_rngData_170 데이터 행 삭제
content = self.text.get(1.0, END)
lines = content.split("\n")
new_content = ""
for line in lines:
    if find_str[i] not in line:
        new_content += line + "\n"
self.text.delete(1.0, END)
self.text.insert(END, new_content)

추가기능으로 특정문자가 포함된 행 을 추가하기

elif find_str[i] == '0': #행추가
    content = self.text.get(1.0, END)
    lines = content.split("\n")
    target_character_rngData = "Set "+replace_str[0]+"_chtChart"
    insert_character_rngData = '    Set {}_rngData_{} = Range(Cells({}, 3), Cells({}, 4 + (find_blank_cell - 1)))'.format(replace_str[0],replace_str[i],replace_str[i],replace_str[i])
    new_content = ""
    for line in lines:
        if target_character_rngData in line:
            new_content += insert_character_rngData + "\n"
        new_content += line + "\n"
    self.text.delete(1.0, END)
    self.text.insert(END, new_content)

참고로 개인적으로 관리하는 파일 관련해서 추가 삭제하는것이라 범용적으론 적용안될수가 있음

728x90
728x90

하나의 글에서 여러문자를 반복해서 바꾸고 싶은데 한번씩 바꾸기 너무 귀찮아서 그냥 만들어버린 프로그램
초보자 답게 예쁘게 다듬는건 없음

결과를 먼저 보면

변경전
바꾸기를 이용해서 한번에 모든 문자열 변경

from tkinter import *
from tkinter import filedialog
from tkinter import messagebox


class Notepad:
    def __init__(self,window):
        # 창 생성
        self.text = Text(window, height=30, width=80)
        self.text.pack()
        window.title("문자열 변경 노트패트")

        # 메뉴를 붙인다
        menu = Menu(window)
        window.config(menu=menu)

        filemenu = Menu(menu)
        menu.add_cascade(label="파일", menu=filemenu)
        filemenu.add_command(label="열기", command=open)
        filemenu.add_command(label="저장하기", command=self.save)
        filemenu.add_command(label="종료", command=exit)

        changemenu = Menu(menu, tearoff=0)  
        menu.add_cascade(label="바꾸기", menu=changemenu)
        changemenu.add_command(label="문자변경프로그램", command=self.change_window)


    def open(self):
        # 파일 대화창을 askopenfile을 이용해서 만들고, 동시에 읽는다
        file = filedialog.askopenfile(parent=self.window, mode='r')
        if file != None:
            lines = file.read()
            # 1.0은 line.column이다.
            # line은 1부터 시작하고 column은 0부터 시작함..
            self.text.insert('1.0', lines)
            file.close()

    def save(self):
        # 쓰고 저장하는 기능
        file = filedialog.asksaveasfile(parent=self.window, mode='w')
        if file != None:
            lines = self.text.get('1.0', END + '-1c')  # 마지막에서 1 char 뺀다, \n제거!
            file.write(lines)
            file.close()

    def exit(self):
        if messagebox.askokcancel("Quit", "종료하시겠습니까?"):
            self.window.destroy()

    def change_window(self):
        window2 = Tk()
        window2.geometry('250x250')
        window2.title("문자열 변경")
        label1 = Label(window2, text="변경 전", bg="light green")
        label1.grid(row=0, column=1)
        self.bf1 = Entry(window2, width=10)
        self.bf1.grid(row=1, column=1)
        self.bf2 = Entry(window2, width=10)
        self.bf2.grid(row=2, column=1)
        self.bf3 = Entry(window2, width=10)
        self.bf3.grid(row=3, column=1)
        self.bf4 = Entry(window2, width=10)
        self.bf4.grid(row=4, column=1)
        self.bf5 = Entry(window2, width=10)
        self.bf5.grid(row=5, column=1)
        self.bf6 = Entry(window2, width=10)
        self.bf6.grid(row=6, column=1)
        self.bf7 = Entry(window2, width=10)
        self.bf7.grid(row=7, column=1)
        self.bf8 = Entry(window2, width=10)
        self.bf8.grid(row=8, column=1)
        self.bf9 = Entry(window2, width=10)
        self.bf9.grid(row=9, column=1)
        self.bf10 = Entry(window2, width=10)
        self.bf10.grid(row=10, column=1)
        label2 = Label(window2, text="변경 후", bg="light blue")
        label2.grid(row=0, column=3)
        self.af1 = Entry(window2, width=10)
        self.af1.grid(row=1, column=3)
        self.af2 = Entry(window2, width=10)
        self.af2.grid(row=2, column=3)
        self.af3 = Entry(window2, width=10)
        self.af3.grid(row=3, column=3)
        self.af4 = Entry(window2, width=10)
        self.af4.grid(row=4, column=3)
        self.af5 = Entry(window2, width=10)
        self.af5.grid(row=5, column=3)
        self.af6 = Entry(window2, width=10)
        self.af6.grid(row=6, column=3)
        self.af7 = Entry(window2, width=10)
        self.af7.grid(row=7, column=3)
        self.af8 = Entry(window2, width=10)
        self.af8.grid(row=8, column=3)
        self.af9 = Entry(window2, width=10)
        self.af9.grid(row=9, column=3)
        self.af10 = Entry(window2, width=10)
        self.af10.grid(row=10, column=3)

        button = Button(window2, text="클   릭", bg="darkorchid", command=self.change_word)
        button.grid(row=12, column=2)

    def change_word(self):
        find_str=[self.bf1.get(),self.bf2.get(),self.bf3.get(),self.bf4.get(),self.bf5.get(),self.bf6.get(),self.bf7.get(),self.bf8.get(),self.bf9.get(),self.bf10.get()]
        replace_str=[self.af1.get(),self.af2.get(),self.af3.get(),self.af4.get(),self.af5.get(),self.af6.get(),self.af7.get(),self.af8.get(),self.af9.get(),self.af10.get()]

        for i in range(len(find_str)):
            if find_str[i] and replace_str[i]:
                content = self.text.get(1.0, END)
                new_content = content.replace(find_str[i], replace_str[i])
                self.text.delete(1.0, END)
                self.text.insert(END, new_content)


if __name__ == "__main__":
    window = Tk()
    notepad = Notepad(window)
    window.mainloop()

 

728x90
728x90

투자자는 자신이 하는일에 대해 인내를 가져야하며, 극단적으로 말한다면 '잠을 잘수 있어야한다.'

일반적 경기변동과 특히 산업부문 경기가 주식의 질과 미래수익을 결정한다. 따라서 한 산업부문의 발전을 몇 년 앞당겨 볼 수 있는 안목을 갖고 있는 사람은 큰돈을 벌 수 있다. 

증권시장의 시세 결정 두가지
1. 통화량과 신주발행
2.심리적 요소. 즉 미래에 대한 예측
시세 = 돈 + 심리

어제까지만 해도 확실했던 것이 오늘은 불확실한 것일 수 있다네. 

모든 사람들이 동시에 하나의 문으로 들어가기 원하게 된다. 그들이 기대했던 시세상승이 일어났음에도 불구하고 바로 그것 때문에 시세는 하락하게 되는것이다.

결정적인 영향을 끼치는 것은 근본적인 사실보다는 환상과 돈이라는 요소이다. 

투자자가 군중 히스테리를 떨쳐버리기 위해서는 많은 훈련을 해야하고 다른사람들을 믿지 말아야하며 조금은 건방진 면이 있어야한다. 

누군가의 투자에서 확실하게 성공하려면, 상황을 정확히 판단해야 할 뿐만아니라 다른 모든 사람들이 잘못되어 있어야 한다는 전제가 필요하다고 말한다.

인간들의 자유로운 생각이 컴퓨터에 의해 통제당하거나 또는 타락할수 있을거라는 적정을 했다. 그래서 모든 직원들의 책상위에 '생각하라'는 말이 적힌 작은 구리표지판을 설치하라고 했다. 

자본주의에서 모험 없이 얻을 수 있는 이익이란 없다. 오늘날의 증기기관, 자동차, 컴퓨터 발명과 도입은 자신들의 돈을 걸고 환상을 자유롭게 좇는 모험가들이 없었다면 결코 불가능했을 것이다. 엄밀하게 말하면, 전 세계가 모험 또는 요즘 말로 '벤처'이다.

주식투자가 장안의 화젯거리가 되는 바로 그 시점에서 투자자들은 무조건 하차해야한다.

투자자는 결코 백과사전이어서는 안된다. 절대로 많은것을 알아서는 안된다. 단지 큰 그림을 이해할수 있으면 된다. 간단히 말해서 그는 생각하는 사람이어야한다.

정보란 털어버릴 주식을 갖고 있거난 또는 수수료를 챙기기를 원하는 은행과 브로커들의 일이다.

사람은 꼭 부자일 필요는 없다. 그보다는 자유로워야한다. 

어르신이 우리한테 해주는 조언이라는 잔소리.
시대도 안맞고 뭔가 말많은 직장상사해 해주는 조언같은 느낌.
다 좋은말인건 알지만 듣기싫은..
여튼 엄청 재밌거나 남는 책은 아니였는듯
728x90

+ Recent posts